diff --git a/.strict-typing b/.strict-typing index f9baa9ac01a..cfccd601ac1 100644 --- a/.strict-typing +++ b/.strict-typing @@ -78,6 +78,7 @@ homeassistant.components.light.* homeassistant.components.local_ip.* homeassistant.components.lock.* homeassistant.components.lookin.* +homeassistant.components.luftdaten.* homeassistant.components.mailbox.* homeassistant.components.media_player.* homeassistant.components.modbus.* diff --git a/homeassistant/components/luftdaten/__init__.py b/homeassistant/components/luftdaten/__init__.py index f131a2dc017..33ddcf67a1e 100644 --- a/homeassistant/components/luftdaten/__init__.py +++ b/homeassistant/components/luftdaten/__init__.py @@ -33,7 +33,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: luftdaten = Luftdaten(entry.data[CONF_SENSOR_ID]) - async def async_update() -> dict[Any, Any]: + async def async_update() -> dict[str, float | int]: """Update sensor/binary sensor data.""" try: await luftdaten.get_data() @@ -43,7 +43,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: if not luftdaten.values: raise UpdateFailed("Did not receive sensor data from luftdaten.info") - data = luftdaten.values + data: dict[str, float | int] = luftdaten.values data.update(luftdaten.meta) return data diff --git a/homeassistant/components/luftdaten/config_flow.py b/homeassistant/components/luftdaten/config_flow.py index febc42e28fd..31f518dcbcf 100644 --- a/homeassistant/components/luftdaten/config_flow.py +++ b/homeassistant/components/luftdaten/config_flow.py @@ -1,5 +1,7 @@ """Config flow to configure the Luftdaten component.""" -from collections import OrderedDict +from __future__ import annotations + +from typing import Any from luftdaten import Luftdaten from luftdaten.exceptions import LuftdatenConnectionError @@ -13,6 +15,7 @@ from homeassistant.const import ( CONF_SHOW_ON_MAP, ) from homeassistant.core import callback +from homeassistant.data_entry_flow import FlowResult import homeassistant.helpers.config_validation as cv from .const import CONF_SENSOR_ID, DEFAULT_SCAN_INTERVAL, DOMAIN @@ -24,17 +27,22 @@ class LuftDatenFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): VERSION = 1 @callback - def _show_form(self, errors=None): + def _show_form(self, errors: dict[str, str] | None = None) -> FlowResult: """Show the form to the user.""" - data_schema = OrderedDict() - data_schema[vol.Required(CONF_SENSOR_ID)] = cv.positive_int - data_schema[vol.Optional(CONF_SHOW_ON_MAP, default=False)] = bool - return self.async_show_form( - step_id="user", data_schema=vol.Schema(data_schema), errors=errors or {} + step_id="user", + data_schema=vol.Schema( + { + vol.Required(CONF_SENSOR_ID): cv.positive_int, + vol.Optional(CONF_SHOW_ON_MAP, default=False): bool, + } + ), + errors=errors or {}, ) - async def async_step_user(self, user_input=None): + async def async_step_user( + self, user_input: dict[str, Any] | None = None + ) -> FlowResult: """Handle the start of the config flow.""" if not user_input: diff --git a/homeassistant/components/luftdaten/sensor.py b/homeassistant/components/luftdaten/sensor.py index 975acf30266..e0bc64bc918 100644 --- a/homeassistant/components/luftdaten/sensor.py +++ b/homeassistant/components/luftdaten/sensor.py @@ -1,6 +1,8 @@ """Support for Luftdaten sensors.""" from __future__ import annotations +from typing import cast + from homeassistant.components.sensor import ( SensorDeviceClass, SensorEntity, @@ -131,4 +133,4 @@ class LuftdatenSensor(CoordinatorEntity, SensorEntity): or (value := self.coordinator.data.get(self.entity_description.key)) is None ): return None - return value + return cast(float, value) diff --git a/mypy.ini b/mypy.ini index 417e3d39d1c..6458bb83932 100644 --- a/mypy.ini +++ b/mypy.ini @@ -869,6 +869,17 @@ no_implicit_optional = true warn_return_any = true warn_unreachable = true +[mypy-homeassistant.components.luftdaten.*] +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.mailbox.*] check_untyped_defs = true disallow_incomplete_defs = true @@ -1919,9 +1930,6 @@ ignore_errors = true [mypy-homeassistant.components.lovelace.*] ignore_errors = true -[mypy-homeassistant.components.luftdaten.*] -ignore_errors = true - [mypy-homeassistant.components.lutron_caseta.*] ignore_errors = true diff --git a/script/hassfest/mypy_config.py b/script/hassfest/mypy_config.py index 220837fd10b..9878fb891e7 100644 --- a/script/hassfest/mypy_config.py +++ b/script/hassfest/mypy_config.py @@ -67,7 +67,6 @@ IGNORED_MODULES: Final[list[str]] = [ "homeassistant.components.litejet.*", "homeassistant.components.litterrobot.*", "homeassistant.components.lovelace.*", - "homeassistant.components.luftdaten.*", "homeassistant.components.lutron_caseta.*", "homeassistant.components.lyric.*", "homeassistant.components.melcloud.*",