diff --git a/.strict-typing b/.strict-typing index 77f7b6f50c2..1832a83641a 100644 --- a/.strict-typing +++ b/.strict-typing @@ -87,6 +87,7 @@ homeassistant.components.emulated_hue.* homeassistant.components.esphome.* homeassistant.components.energy.* homeassistant.components.evil_genius_labs.* +homeassistant.components.fan.* homeassistant.components.fastdotcom.* homeassistant.components.filesize.* homeassistant.components.fitbit.* diff --git a/homeassistant/components/fan/__init__.py b/homeassistant/components/fan/__init__.py index 5eb3bedabd5..8f6585f6535 100644 --- a/homeassistant/components/fan/__init__.py +++ b/homeassistant/components/fan/__init__.py @@ -7,7 +7,7 @@ from enum import IntEnum import functools as ft import logging import math -from typing import final +from typing import Any, final import voluptuous as vol @@ -80,9 +80,11 @@ class NotValidPresetModeError(ValueError): @bind_hass -def is_on(hass, entity_id: str) -> bool: +def is_on(hass: HomeAssistant, entity_id: str) -> bool: """Return if the fans are on based on the statemachine.""" - return hass.states.get(entity_id).state == STATE_ON + entity = hass.states.get(entity_id) + assert entity + return entity.state == STATE_ON async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: @@ -235,7 +237,7 @@ class FanEntity(ToggleEntity): """Set new preset mode.""" await self.hass.async_add_executor_job(self.set_preset_mode, preset_mode) - def _valid_preset_mode_or_raise(self, preset_mode): + def _valid_preset_mode_or_raise(self, preset_mode: str) -> None: """Raise NotValidPresetModeError on invalid preset_mode.""" preset_modes = self.preset_modes if not preset_modes or preset_mode not in preset_modes: @@ -247,7 +249,7 @@ class FanEntity(ToggleEntity): """Set the direction of the fan.""" raise NotImplementedError() - async def async_set_direction(self, direction: str): + async def async_set_direction(self, direction: str) -> None: """Set the direction of the fan.""" await self.hass.async_add_executor_job(self.set_direction, direction) @@ -255,7 +257,7 @@ class FanEntity(ToggleEntity): self, percentage: int | None = None, preset_mode: str | None = None, - **kwargs, + **kwargs: Any, ) -> None: """Turn on the fan.""" raise NotImplementedError() @@ -264,7 +266,7 @@ class FanEntity(ToggleEntity): self, percentage: int | None = None, preset_mode: str | None = None, - **kwargs, + **kwargs: Any, ) -> None: """Turn on the fan.""" await self.hass.async_add_executor_job( @@ -280,12 +282,12 @@ class FanEntity(ToggleEntity): """Oscillate the fan.""" raise NotImplementedError() - async def async_oscillate(self, oscillating: bool): + async def async_oscillate(self, oscillating: bool) -> None: """Oscillate the fan.""" await self.hass.async_add_executor_job(self.oscillate, oscillating) @property - def is_on(self): + def is_on(self) -> bool | None: """Return true if the entity is on.""" return ( self.percentage is not None and self.percentage > 0 @@ -321,7 +323,7 @@ class FanEntity(ToggleEntity): return self._attr_oscillating @property - def capability_attributes(self): + def capability_attributes(self) -> dict[str, list[str] | None]: """Return capability attributes.""" attrs = {} @@ -335,7 +337,7 @@ class FanEntity(ToggleEntity): @final @property - def state_attributes(self) -> dict: + def state_attributes(self) -> dict[str, float | str | None]: """Return optional state attributes.""" data: dict[str, float | str | None] = {} supported_features = self.supported_features diff --git a/homeassistant/components/vallox/fan.py b/homeassistant/components/vallox/fan.py index 6872acbb5b7..4ba7d2d88fd 100644 --- a/homeassistant/components/vallox/fan.py +++ b/homeassistant/components/vallox/fan.py @@ -132,7 +132,7 @@ class ValloxFan(ValloxEntity, FanEntity): Returns true if the mode has been changed, false otherwise. """ try: - self._valid_preset_mode_or_raise(preset_mode) # type: ignore[no-untyped-call] + self._valid_preset_mode_or_raise(preset_mode) except NotValidPresetModeError as err: _LOGGER.error(err) diff --git a/mypy.ini b/mypy.ini index 19241872474..8dca7403eff 100644 --- a/mypy.ini +++ b/mypy.ini @@ -720,6 +720,17 @@ no_implicit_optional = true warn_return_any = true warn_unreachable = true +[mypy-homeassistant.components.fan.*] +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.fastdotcom.*] check_untyped_defs = true disallow_incomplete_defs = true