From 6b6e5fad3c5869f5c5a9b6cc32e6656b01e13884 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Wed, 22 Jun 2022 18:43:41 +0200 Subject: [PATCH] Add missing type hints in fans (#73835) --- homeassistant/components/comfoconnect/fan.py | 2 +- homeassistant/components/demo/fan.py | 14 ++++--- homeassistant/components/fjaraskupan/fan.py | 8 ++-- homeassistant/components/freedompro/fan.py | 4 +- homeassistant/components/insteon/fan.py | 7 ++-- homeassistant/components/lutron_caseta/fan.py | 10 +++-- homeassistant/components/modern_forms/fan.py | 2 +- homeassistant/components/mqtt/fan.py | 15 +++---- homeassistant/components/smartthings/fan.py | 3 +- homeassistant/components/smarty/fan.py | 10 ++++- homeassistant/components/switch_as_x/fan.py | 4 +- homeassistant/components/template/fan.py | 16 ++++---- homeassistant/components/tuya/fan.py | 4 +- homeassistant/components/vesync/fan.py | 17 ++++---- homeassistant/components/wilight/fan.py | 14 ++++--- homeassistant/components/xiaomi_miio/fan.py | 41 ++++++++++--------- homeassistant/components/zha/fan.py | 8 +++- homeassistant/components/zwave_me/fan.py | 2 +- 18 files changed, 106 insertions(+), 75 deletions(-) diff --git a/homeassistant/components/comfoconnect/fan.py b/homeassistant/components/comfoconnect/fan.py index 84d82c170e1..f52c065a547 100644 --- a/homeassistant/components/comfoconnect/fan.py +++ b/homeassistant/components/comfoconnect/fan.py @@ -118,7 +118,7 @@ class ComfoConnectFan(FanEntity): self, percentage: int | None = None, preset_mode: str | None = None, - **kwargs, + **kwargs: Any, ) -> None: """Turn on the fan.""" if percentage is None: diff --git a/homeassistant/components/demo/fan.py b/homeassistant/components/demo/fan.py index 66440588f17..ef6875cb7c6 100644 --- a/homeassistant/components/demo/fan.py +++ b/homeassistant/components/demo/fan.py @@ -1,6 +1,8 @@ """Demo fan platform that has a fake fan.""" from __future__ import annotations +from typing import Any + from homeassistant.components.fan import FanEntity, FanEntityFeature from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant @@ -192,9 +194,9 @@ class DemoPercentageFan(BaseDemoFan, FanEntity): def turn_on( self, - percentage: int = None, - preset_mode: str = None, - **kwargs, + percentage: int | None = None, + preset_mode: str | None = None, + **kwargs: Any, ) -> None: """Turn on the entity.""" if preset_mode: @@ -262,9 +264,9 @@ class AsyncDemoPercentageFan(BaseDemoFan, FanEntity): async def async_turn_on( self, - percentage: int = None, - preset_mode: str = None, - **kwargs, + percentage: int | None = None, + preset_mode: str | None = None, + **kwargs: Any, ) -> None: """Turn on the entity.""" if preset_mode: diff --git a/homeassistant/components/fjaraskupan/fan.py b/homeassistant/components/fjaraskupan/fan.py index fcd95090400..ae5da3d189c 100644 --- a/homeassistant/components/fjaraskupan/fan.py +++ b/homeassistant/components/fjaraskupan/fan.py @@ -1,6 +1,8 @@ """Support for Fjäråskupan fans.""" from __future__ import annotations +from typing import Any + from fjaraskupan import ( COMMAND_AFTERCOOKINGTIMERAUTO, COMMAND_AFTERCOOKINGTIMERMANUAL, @@ -93,9 +95,9 @@ class Fan(CoordinatorEntity[Coordinator], FanEntity): async def async_turn_on( self, - percentage: int = None, - preset_mode: str = None, - **kwargs, + percentage: int | None = None, + preset_mode: str | None = None, + **kwargs: Any, ) -> None: """Turn on the fan.""" diff --git a/homeassistant/components/freedompro/fan.py b/homeassistant/components/freedompro/fan.py index b7758813865..3513b7672e0 100644 --- a/homeassistant/components/freedompro/fan.py +++ b/homeassistant/components/freedompro/fan.py @@ -60,7 +60,7 @@ class FreedomproFan(CoordinatorEntity, FanEntity): return self._attr_is_on @property - def percentage(self): + def percentage(self) -> int | None: """Return the current speed percentage.""" return self._attr_percentage @@ -111,7 +111,7 @@ class FreedomproFan(CoordinatorEntity, FanEntity): ) await self.coordinator.async_request_refresh() - async def async_set_percentage(self, percentage: int): + async def async_set_percentage(self, percentage: int) -> None: """Set the speed percentage of the fan.""" rotation_speed = {"rotationSpeed": percentage} payload = json.dumps(rotation_speed) diff --git a/homeassistant/components/insteon/fan.py b/homeassistant/components/insteon/fan.py index 8639dfb79fe..8fe5fc9346e 100644 --- a/homeassistant/components/insteon/fan.py +++ b/homeassistant/components/insteon/fan.py @@ -2,6 +2,7 @@ from __future__ import annotations import math +from typing import Any from homeassistant.components.fan import ( DOMAIN as FAN_DOMAIN, @@ -62,9 +63,9 @@ class InsteonFanEntity(InsteonEntity, FanEntity): async def async_turn_on( self, - percentage: int = None, - preset_mode: str = None, - **kwargs, + percentage: int | None = None, + preset_mode: str | None = None, + **kwargs: Any, ) -> None: """Turn on the fan.""" await self.async_set_percentage(percentage or 67) diff --git a/homeassistant/components/lutron_caseta/fan.py b/homeassistant/components/lutron_caseta/fan.py index e08a5278572..44dae8324fa 100644 --- a/homeassistant/components/lutron_caseta/fan.py +++ b/homeassistant/components/lutron_caseta/fan.py @@ -1,6 +1,8 @@ """Support for Lutron Caseta fans.""" from __future__ import annotations +from typing import Any + from pylutron_caseta import FAN_HIGH, FAN_LOW, FAN_MEDIUM, FAN_MEDIUM_HIGH, FAN_OFF from homeassistant.components.fan import DOMAIN, FanEntity, FanEntityFeature @@ -58,10 +60,10 @@ class LutronCasetaFan(LutronCasetaDeviceUpdatableEntity, FanEntity): async def async_turn_on( self, - percentage: int = None, - preset_mode: str = None, - **kwargs, - ): + percentage: int | None = None, + preset_mode: str | None = None, + **kwargs: Any, + ) -> None: """Turn the fan on.""" if percentage is None: percentage = DEFAULT_ON_PERCENTAGE diff --git a/homeassistant/components/modern_forms/fan.py b/homeassistant/components/modern_forms/fan.py index 318bb8c969d..8bd8665dc3b 100644 --- a/homeassistant/components/modern_forms/fan.py +++ b/homeassistant/components/modern_forms/fan.py @@ -127,7 +127,7 @@ class ModernFormsFanEntity(FanEntity, ModernFormsDeviceEntity): async def async_turn_on( self, percentage: int | None = None, - preset_mode: int | None = None, + preset_mode: str | None = None, **kwargs: Any, ) -> None: """Turn on the fan.""" diff --git a/homeassistant/components/mqtt/fan.py b/homeassistant/components/mqtt/fan.py index 4e1d1465ac2..4e7e58afb9f 100644 --- a/homeassistant/components/mqtt/fan.py +++ b/homeassistant/components/mqtt/fan.py @@ -4,6 +4,7 @@ from __future__ import annotations import functools import logging import math +from typing import Any import voluptuous as vol @@ -511,17 +512,17 @@ class MqttFan(MqttEntity, FanEntity): return self._state @property - def percentage(self): + def percentage(self) -> int | None: """Return the current percentage.""" return self._percentage @property - def preset_mode(self): + def preset_mode(self) -> str | None: """Return the current preset _mode.""" return self._preset_mode @property - def preset_modes(self) -> list: + def preset_modes(self) -> list[str]: """Get the list of available preset modes.""" return self._preset_modes @@ -536,16 +537,16 @@ class MqttFan(MqttEntity, FanEntity): return self._speed_count @property - def oscillating(self): + def oscillating(self) -> bool | None: """Return the oscillation state.""" return self._oscillation # The speed attribute deprecated in the schema, support will be removed after a quarter (2021.7) async def async_turn_on( self, - percentage: int = None, - preset_mode: str = None, - **kwargs, + percentage: int | None = None, + preset_mode: str | None = None, + **kwargs: Any, ) -> None: """Turn on the entity. diff --git a/homeassistant/components/smartthings/fan.py b/homeassistant/components/smartthings/fan.py index 36d47533bbb..abcd5d12f75 100644 --- a/homeassistant/components/smartthings/fan.py +++ b/homeassistant/components/smartthings/fan.py @@ -3,6 +3,7 @@ from __future__ import annotations from collections.abc import Sequence import math +from typing import Any from pysmartthings import Capability @@ -72,7 +73,7 @@ class SmartThingsFan(SmartThingsEntity, FanEntity): self, percentage: int | None = None, preset_mode: str | None = None, - **kwargs, + **kwargs: Any, ) -> None: """Turn the fan on.""" await self._async_set_percentage(percentage) diff --git a/homeassistant/components/smarty/fan.py b/homeassistant/components/smarty/fan.py index 531b96d2558..a51d6783245 100644 --- a/homeassistant/components/smarty/fan.py +++ b/homeassistant/components/smarty/fan.py @@ -3,6 +3,7 @@ from __future__ import annotations import logging import math +from typing import Any from homeassistant.components.fan import FanEntity, FanEntityFeature from homeassistant.core import HomeAssistant, callback @@ -64,7 +65,7 @@ class SmartyFan(FanEntity): return "mdi:air-conditioner" @property - def is_on(self): + def is_on(self) -> bool: """Return state of the fan.""" return bool(self._smarty_fan_speed) @@ -96,7 +97,12 @@ class SmartyFan(FanEntity): self._smarty_fan_speed = fan_speed self.schedule_update_ha_state() - def turn_on(self, percentage=None, preset_mode=None, **kwargs): + def turn_on( + self, + percentage: int | None = None, + preset_mode: str | None = None, + **kwargs: Any, + ) -> None: """Turn on the fan.""" _LOGGER.debug("Turning on fan. percentage is %s", percentage) self.set_percentage(percentage or DEFAULT_ON_PERCENTAGE) diff --git a/homeassistant/components/switch_as_x/fan.py b/homeassistant/components/switch_as_x/fan.py index 5ebc8902d06..d4f16a93ef6 100644 --- a/homeassistant/components/switch_as_x/fan.py +++ b/homeassistant/components/switch_as_x/fan.py @@ -1,6 +1,8 @@ """Fan support for switch entities.""" from __future__ import annotations +from typing import Any + from homeassistant.components.fan import FanEntity from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_ENTITY_ID @@ -53,7 +55,7 @@ class FanSwitch(BaseToggleEntity, FanEntity): self, percentage: int | None = None, preset_mode: str | None = None, - **kwargs, + **kwargs: Any, ) -> None: """Turn on the fan. diff --git a/homeassistant/components/template/fan.py b/homeassistant/components/template/fan.py index ca50f6017bd..67cbeb07170 100644 --- a/homeassistant/components/template/fan.py +++ b/homeassistant/components/template/fan.py @@ -215,35 +215,35 @@ class TemplateFan(TemplateEntity, FanEntity): return self._preset_modes @property - def is_on(self): + def is_on(self) -> bool: """Return true if device is on.""" return self._state == STATE_ON @property - def preset_mode(self): + def preset_mode(self) -> str | None: """Return the current preset mode.""" return self._preset_mode @property - def percentage(self): + def percentage(self) -> int | None: """Return the current speed percentage.""" return self._percentage @property - def oscillating(self): + def oscillating(self) -> bool | None: """Return the oscillation state.""" return self._oscillating @property - def current_direction(self): + def current_direction(self) -> str | None: """Return the oscillation state.""" return self._direction async def async_turn_on( self, - percentage: int = None, - preset_mode: str = None, - **kwargs, + percentage: int | None = None, + preset_mode: str | None = None, + **kwargs: Any, ) -> None: """Turn on the fan.""" await self.async_run_script( diff --git a/homeassistant/components/tuya/fan.py b/homeassistant/components/tuya/fan.py index 2d16ed36d40..36ed4c3c58e 100644 --- a/homeassistant/components/tuya/fan.py +++ b/homeassistant/components/tuya/fan.py @@ -158,8 +158,8 @@ class TuyaFanEntity(TuyaEntity, FanEntity): def turn_on( self, - percentage: int = None, - preset_mode: str = None, + percentage: int | None = None, + preset_mode: str | None = None, **kwargs: Any, ) -> None: """Turn on the fan.""" diff --git a/homeassistant/components/vesync/fan.py b/homeassistant/components/vesync/fan.py index 44e74209c30..696a6a9ecf9 100644 --- a/homeassistant/components/vesync/fan.py +++ b/homeassistant/components/vesync/fan.py @@ -1,6 +1,9 @@ """Support for VeSync fans.""" +from __future__ import annotations + import logging import math +from typing import Any from homeassistant.components.fan import FanEntity, FanEntityFeature from homeassistant.config_entries import ConfigEntry @@ -91,7 +94,7 @@ class VeSyncFanHA(VeSyncDevice, FanEntity): self.smartfan = fan @property - def percentage(self): + def percentage(self) -> int | None: """Return the current speed.""" if ( self.smartfan.mode == "manual" @@ -115,7 +118,7 @@ class VeSyncFanHA(VeSyncDevice, FanEntity): return PRESET_MODES[SKU_TO_BASE_DEVICE.get(self.device.device_type)] @property - def preset_mode(self): + def preset_mode(self) -> str | None: """Get the current preset mode.""" if self.smartfan.mode in (FAN_MODE_AUTO, FAN_MODE_SLEEP): return self.smartfan.mode @@ -148,7 +151,7 @@ class VeSyncFanHA(VeSyncDevice, FanEntity): return attr - def set_percentage(self, percentage): + def set_percentage(self, percentage: int) -> None: """Set the speed of the device.""" if percentage == 0: self.smartfan.turn_off() @@ -167,7 +170,7 @@ class VeSyncFanHA(VeSyncDevice, FanEntity): ) self.schedule_update_ha_state() - def set_preset_mode(self, preset_mode): + def set_preset_mode(self, preset_mode: str) -> None: """Set the preset mode of device.""" if preset_mode not in self.preset_modes: raise ValueError( @@ -187,9 +190,9 @@ class VeSyncFanHA(VeSyncDevice, FanEntity): def turn_on( self, - percentage: int = None, - preset_mode: str = None, - **kwargs, + percentage: int | None = None, + preset_mode: str | None = None, + **kwargs: Any, ) -> None: """Turn the device on.""" if preset_mode: diff --git a/homeassistant/components/wilight/fan.py b/homeassistant/components/wilight/fan.py index b96b4b89c61..7a60fa8ab62 100644 --- a/homeassistant/components/wilight/fan.py +++ b/homeassistant/components/wilight/fan.py @@ -1,6 +1,8 @@ """Support for WiLight Fan.""" from __future__ import annotations +from typing import Any + from pywilight.const import ( FAN_V1, ITEM_FAN, @@ -64,7 +66,7 @@ class WiLightFan(WiLightDevice, FanEntity): return "mdi:fan" @property - def is_on(self): + def is_on(self) -> bool: """Return true if device is on.""" return self._status.get("direction", WL_DIRECTION_OFF) != WL_DIRECTION_OFF @@ -98,9 +100,9 @@ class WiLightFan(WiLightDevice, FanEntity): async def async_turn_on( self, - percentage: int = None, - preset_mode: str = None, - **kwargs, + percentage: int | None = None, + preset_mode: str | None = None, + **kwargs: Any, ) -> None: """Turn on the fan.""" if percentage is None: @@ -108,7 +110,7 @@ class WiLightFan(WiLightDevice, FanEntity): else: await self.async_set_percentage(percentage) - async def async_set_percentage(self, percentage: int): + async def async_set_percentage(self, percentage: int) -> None: """Set the speed of the fan.""" if percentage == 0: await self._client.set_fan_direction(self._index, WL_DIRECTION_OFF) @@ -121,7 +123,7 @@ class WiLightFan(WiLightDevice, FanEntity): wl_speed = percentage_to_ordered_list_item(ORDERED_NAMED_FAN_SPEEDS, percentage) await self._client.set_fan_speed(self._index, wl_speed) - async def async_set_direction(self, direction: str): + async def async_set_direction(self, direction: str) -> None: """Set the direction of the fan.""" wl_direction = WL_DIRECTION_REVERSE if direction == DIRECTION_FORWARD: diff --git a/homeassistant/components/xiaomi_miio/fan.py b/homeassistant/components/xiaomi_miio/fan.py index 969093545f0..31908ba373f 100644 --- a/homeassistant/components/xiaomi_miio/fan.py +++ b/homeassistant/components/xiaomi_miio/fan.py @@ -1,8 +1,11 @@ """Support for Xiaomi Mi Air Purifier and Xiaomi Mi Air Humidifier.""" +from __future__ import annotations + from abc import abstractmethod import asyncio import logging import math +from typing import Any from miio.airfresh import OperationMode as AirfreshOperationMode from miio.airfresh_t2017 import OperationMode as AirfreshOperationModeT2017 @@ -291,12 +294,12 @@ class XiaomiGenericDevice(XiaomiCoordinatedMiioEntity, FanEntity): """Hold operation mode class.""" @property - def preset_modes(self) -> list: + def preset_modes(self) -> list[str]: """Get the list of available preset modes.""" return self._preset_modes @property - def percentage(self): + def percentage(self) -> None: """Return the percentage based speed of the fan.""" return None @@ -306,15 +309,15 @@ class XiaomiGenericDevice(XiaomiCoordinatedMiioEntity, FanEntity): return self._state_attrs @property - def is_on(self): + def is_on(self) -> bool | None: """Return true if device is on.""" return self._state async def async_turn_on( self, - percentage: int = None, - preset_mode: str = None, - **kwargs, + percentage: int | None = None, + preset_mode: str | None = None, + **kwargs: Any, ) -> None: """Turn the device on.""" result = await self._try_command( @@ -352,12 +355,12 @@ class XiaomiGenericAirPurifier(XiaomiGenericDevice): self._speed_count = 100 @property - def speed_count(self): + def speed_count(self) -> int: """Return the number of speeds of the fan supported.""" return self._speed_count @property - def preset_mode(self): + def preset_mode(self) -> str | None: """Get the active preset mode.""" if self._state: preset_mode = self.operation_mode_class(self._mode).name @@ -451,7 +454,7 @@ class XiaomiAirPurifier(XiaomiGenericAirPurifier): return AirpurifierOperationMode @property - def percentage(self): + def percentage(self) -> int | None: """Return the current percentage based speed.""" if self._state: mode = self.operation_mode_class(self._mode) @@ -528,7 +531,7 @@ class XiaomiAirPurifierMiot(XiaomiAirPurifier): return AirpurifierMiotOperationMode @property - def percentage(self): + def percentage(self) -> int | None: """Return the current percentage based speed.""" if self._fan_level is None: return None @@ -642,7 +645,7 @@ class XiaomiAirFresh(XiaomiGenericAirPurifier): return AirfreshOperationMode @property - def percentage(self): + def percentage(self) -> int | None: """Return the current percentage based speed.""" if self._state: mode = AirfreshOperationMode(self._mode) @@ -733,7 +736,7 @@ class XiaomiAirFreshA1(XiaomiGenericAirPurifier): return AirfreshOperationModeT2017 @property - def percentage(self): + def percentage(self) -> int | None: """Return the current percentage based speed.""" if self._favorite_speed is None: return None @@ -826,17 +829,17 @@ class XiaomiGenericFan(XiaomiGenericDevice): self._percentage = None @property - def preset_mode(self): + def preset_mode(self) -> str | None: """Get the active preset mode.""" return self._preset_mode @property - def preset_modes(self) -> list: + def preset_modes(self) -> list[str]: """Get the list of available preset modes.""" return [mode.name for mode in self.operation_mode_class] @property - def percentage(self): + def percentage(self) -> int | None: """Return the current speed as a percentage.""" if self._state: return self._percentage @@ -844,7 +847,7 @@ class XiaomiGenericFan(XiaomiGenericDevice): return None @property - def oscillating(self): + def oscillating(self) -> bool | None: """Return whether or not the fan is currently oscillating.""" return self._oscillating @@ -890,12 +893,12 @@ class XiaomiFan(XiaomiGenericFan): """Hold operation mode class.""" @property - def preset_mode(self): + def preset_mode(self) -> str: """Get the active preset mode.""" return ATTR_MODE_NATURE if self._nature_mode else ATTR_MODE_NORMAL @property - def preset_modes(self) -> list: + def preset_modes(self) -> list[str]: """Get the list of available preset modes.""" return [ATTR_MODE_NATURE, ATTR_MODE_NORMAL] @@ -1030,7 +1033,7 @@ class XiaomiFanMiot(XiaomiGenericFan): return FanOperationMode @property - def preset_mode(self): + def preset_mode(self) -> str | None: """Get the active preset mode.""" return self._preset_mode diff --git a/homeassistant/components/zha/fan.py b/homeassistant/components/zha/fan.py index a4b9baa5f0a..298f9e47296 100644 --- a/homeassistant/components/zha/fan.py +++ b/homeassistant/components/zha/fan.py @@ -4,6 +4,7 @@ from __future__ import annotations from abc import abstractmethod import functools import math +from typing import Any from zigpy.exceptions import ZigbeeException from zigpy.zcl.clusters import hvac @@ -87,7 +88,12 @@ class BaseFan(FanEntity): """Return the number of speeds the fan supports.""" return int_states_in_range(SPEED_RANGE) - async def async_turn_on(self, percentage=None, preset_mode=None, **kwargs) -> None: + async def async_turn_on( + self, + percentage: int | None = None, + preset_mode: str | None = None, + **kwargs: Any, + ) -> None: """Turn the entity on.""" if percentage is None: percentage = DEFAULT_ON_PERCENTAGE diff --git a/homeassistant/components/zwave_me/fan.py b/homeassistant/components/zwave_me/fan.py index 45d238a6541..c332fb305c5 100644 --- a/homeassistant/components/zwave_me/fan.py +++ b/homeassistant/components/zwave_me/fan.py @@ -66,7 +66,7 @@ class ZWaveMeFan(ZWaveMeEntity, FanEntity): self, percentage: int | None = None, preset_mode: str | None = None, - **kwargs, + **kwargs: Any, ) -> None: """Turn on the fan.""" self.set_percentage(percentage if percentage is not None else 99)