From a2be9a487f52c41789793f54ef61864734b91cc3 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Thu, 24 Jun 2021 20:27:25 +0200 Subject: [PATCH] DSMR: Complete full strictly typed (#52162) --- .strict-typing | 1 + homeassistant/components/dsmr/config_flow.py | 8 +++++--- homeassistant/components/dsmr/sensor.py | 5 +++-- mypy.ini | 11 +++++++++++ 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/.strict-typing b/.strict-typing index 1112dfba9ae..cde4d314cca 100644 --- a/.strict-typing +++ b/.strict-typing @@ -26,6 +26,7 @@ homeassistant.components.cover.* homeassistant.components.device_automation.* homeassistant.components.device_tracker.* homeassistant.components.dnsip.* +homeassistant.components.dsmr.* homeassistant.components.dunehd.* homeassistant.components.elgato.* homeassistant.components.fitbit.* diff --git a/homeassistant/components/dsmr/config_flow.py b/homeassistant/components/dsmr/config_flow.py index 294526a386e..72e854fe43a 100644 --- a/homeassistant/components/dsmr/config_flow.py +++ b/homeassistant/components/dsmr/config_flow.py @@ -51,14 +51,16 @@ class DSMRConnection: """Equipment identifier.""" if self._equipment_identifier in self._telegram: dsmr_object = self._telegram[self._equipment_identifier] - return getattr(dsmr_object, "value", None) + identifier: str | None = getattr(dsmr_object, "value", None) + return identifier return None def equipment_identifier_gas(self) -> str | None: """Equipment identifier gas.""" if obis_ref.EQUIPMENT_IDENTIFIER_GAS in self._telegram: dsmr_object = self._telegram[obis_ref.EQUIPMENT_IDENTIFIER_GAS] - return getattr(dsmr_object, "value", None) + identifier: str | None = getattr(dsmr_object, "value", None) + return identifier return None async def validate_connect(self, hass: core.HomeAssistant) -> bool: @@ -142,7 +144,7 @@ class DSMRFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): def _abort_if_host_port_configured( self, port: str, - host: str = None, + host: str | None = None, updates: dict[Any, Any] | None = None, reload_on_update: bool = True, ) -> FlowResult | None: diff --git a/homeassistant/components/dsmr/sensor.py b/homeassistant/components/dsmr/sensor.py index c514447b4d7..42c8dd7fd54 100644 --- a/homeassistant/components/dsmr/sensor.py +++ b/homeassistant/components/dsmr/sensor.py @@ -89,7 +89,7 @@ async def async_setup_entry( ) @Throttle(min_time_between_updates) - def update_entities_telegram(telegram: dict[str, DSMRObject]): + def update_entities_telegram(telegram: dict[str, DSMRObject]) -> None: """Update entities with latest telegram and trigger state update.""" # Make all device entities aware of new telegram for entity in entities: @@ -222,7 +222,8 @@ class DSMREntity(SensorEntity): # Get the attribute value if the object has it dsmr_object = self.telegram[self._sensor.obis_reference] - return getattr(dsmr_object, attribute, None) + attr: str | None = getattr(dsmr_object, attribute) + return attr @property def state(self) -> StateType: diff --git a/mypy.ini b/mypy.ini index 505d02b1111..c7fa78efecf 100644 --- a/mypy.ini +++ b/mypy.ini @@ -297,6 +297,17 @@ no_implicit_optional = true warn_return_any = true warn_unreachable = true +[mypy-homeassistant.components.dsmr.*] +check_untyped_defs = true +disallow_incomplete_defs = true +disallow_subclassing_any = true +disallow_untyped_calls = true +disallow_untyped_decorators = true +disallow_untyped_defs = true +no_implicit_optional = true +warn_return_any = true +warn_unreachable = true + [mypy-homeassistant.components.dunehd.*] check_untyped_defs = true disallow_incomplete_defs = true