From 3e334a4950ae8620167a2c470b42ebdb8dd88dfb Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 19 Feb 2021 19:57:21 -1000 Subject: [PATCH] Fix typing of fan speed count and steps (#46790) --- homeassistant/components/bond/fan.py | 2 +- homeassistant/components/demo/fan.py | 4 ++-- homeassistant/components/dyson/fan.py | 2 +- homeassistant/components/esphome/fan.py | 2 +- homeassistant/components/fan/__init__.py | 12 +++++++----- homeassistant/components/knx/fan.py | 2 +- homeassistant/components/smartthings/fan.py | 2 +- homeassistant/components/tuya/fan.py | 2 +- homeassistant/components/zwave_js/fan.py | 2 +- 9 files changed, 16 insertions(+), 14 deletions(-) diff --git a/homeassistant/components/bond/fan.py b/homeassistant/components/bond/fan.py index cef2efae690..5ff7e0c7065 100644 --- a/homeassistant/components/bond/fan.py +++ b/homeassistant/components/bond/fan.py @@ -87,7 +87,7 @@ class BondFan(BondEntity, FanEntity): return ranged_value_to_percentage(self._speed_range, self._speed) @property - def speed_count(self) -> Optional[int]: + def speed_count(self) -> int: """Return the number of speeds the fan supports.""" return int_states_in_range(self._speed_range) diff --git a/homeassistant/components/demo/fan.py b/homeassistant/components/demo/fan.py index 6bbd8b81f6d..c79b53c0918 100644 --- a/homeassistant/components/demo/fan.py +++ b/homeassistant/components/demo/fan.py @@ -216,7 +216,7 @@ class DemoPercentageFan(BaseDemoFan, FanEntity): return self._percentage @property - def speed_count(self) -> Optional[float]: + def speed_count(self) -> int: """Return the number of speeds the fan supports.""" return 3 @@ -276,7 +276,7 @@ class AsyncDemoPercentageFan(BaseDemoFan, FanEntity): return self._percentage @property - def speed_count(self) -> Optional[float]: + def speed_count(self) -> int: """Return the number of speeds the fan supports.""" return 3 diff --git a/homeassistant/components/dyson/fan.py b/homeassistant/components/dyson/fan.py index 9e49badbc8e..a8e737bb48b 100644 --- a/homeassistant/components/dyson/fan.py +++ b/homeassistant/components/dyson/fan.py @@ -156,7 +156,7 @@ class DysonFanEntity(DysonEntity, FanEntity): return ranged_value_to_percentage(SPEED_RANGE, int(self._device.state.speed)) @property - def speed_count(self) -> Optional[int]: + def speed_count(self) -> int: """Return the number of speeds the fan supports.""" return int_states_in_range(SPEED_RANGE) diff --git a/homeassistant/components/esphome/fan.py b/homeassistant/components/esphome/fan.py index 092c416acab..df23f37cb63 100644 --- a/homeassistant/components/esphome/fan.py +++ b/homeassistant/components/esphome/fan.py @@ -120,7 +120,7 @@ class EsphomeFan(EsphomeEntity, FanEntity): ) @property - def speed_count(self) -> Optional[int]: + def speed_count(self) -> int: """Return the number of speeds the fan supports.""" return len(ORDERED_NAMED_FAN_SPEEDS) diff --git a/homeassistant/components/fan/__init__.py b/homeassistant/components/fan/__init__.py index 692588cff48..18f46b3d619 100644 --- a/homeassistant/components/fan/__init__.py +++ b/homeassistant/components/fan/__init__.py @@ -272,15 +272,17 @@ class FanEntity(ToggleEntity): else: await self.async_set_speed(self.percentage_to_speed(percentage)) - async def async_increase_speed(self, percentage_step=None) -> None: + async def async_increase_speed(self, percentage_step: Optional[int] = None) -> None: """Increase the speed of the fan.""" await self._async_adjust_speed(1, percentage_step) - async def async_decrease_speed(self, percentage_step=None) -> None: + async def async_decrease_speed(self, percentage_step: Optional[int] = None) -> None: """Decrease the speed of the fan.""" await self._async_adjust_speed(-1, percentage_step) - async def _async_adjust_speed(self, modifier, percentage_step) -> None: + async def _async_adjust_speed( + self, modifier: int, percentage_step: Optional[int] + ) -> None: """Increase or decrease the speed of the fan.""" current_percentage = self.percentage or 0 @@ -462,7 +464,7 @@ class FanEntity(ToggleEntity): return 0 @property - def speed_count(self) -> Optional[int]: + def speed_count(self) -> int: """Return the number of speeds the fan supports.""" speed_list = speed_list_without_preset_modes(self.speed_list) if speed_list: @@ -470,7 +472,7 @@ class FanEntity(ToggleEntity): return 100 @property - def percentage_step(self) -> Optional[float]: + def percentage_step(self) -> float: """Return the step size for percentage.""" return 100 / self.speed_count diff --git a/homeassistant/components/knx/fan.py b/homeassistant/components/knx/fan.py index d0b7b4c5546..6aa4f722892 100644 --- a/homeassistant/components/knx/fan.py +++ b/homeassistant/components/knx/fan.py @@ -70,7 +70,7 @@ class KNXFan(KnxEntity, FanEntity): return self._device.current_speed @property - def speed_count(self) -> Optional[int]: + def speed_count(self) -> int: """Return the number of speeds the fan supports.""" if self._step_range is None: return super().speed_count diff --git a/homeassistant/components/smartthings/fan.py b/homeassistant/components/smartthings/fan.py index 12edac36dfe..4cd451e2416 100644 --- a/homeassistant/components/smartthings/fan.py +++ b/homeassistant/components/smartthings/fan.py @@ -81,7 +81,7 @@ class SmartThingsFan(SmartThingsEntity, FanEntity): return ranged_value_to_percentage(SPEED_RANGE, self._device.status.fan_speed) @property - def speed_count(self) -> Optional[int]: + def speed_count(self) -> int: """Return the number of speeds the fan supports.""" return int_states_in_range(SPEED_RANGE) diff --git a/homeassistant/components/tuya/fan.py b/homeassistant/components/tuya/fan.py index 4c555bb942a..cb6f96358c9 100644 --- a/homeassistant/components/tuya/fan.py +++ b/homeassistant/components/tuya/fan.py @@ -103,7 +103,7 @@ class TuyaFanDevice(TuyaDevice, FanEntity): self._tuya.oscillate(oscillating) @property - def speed_count(self) -> Optional[int]: + def speed_count(self) -> int: """Return the number of speeds the fan supports.""" if self.speeds is None: return super().speed_count diff --git a/homeassistant/components/zwave_js/fan.py b/homeassistant/components/zwave_js/fan.py index ae903d9efaf..ea17fbe4cff 100644 --- a/homeassistant/components/zwave_js/fan.py +++ b/homeassistant/components/zwave_js/fan.py @@ -98,7 +98,7 @@ class ZwaveFan(ZWaveBaseEntity, FanEntity): return ranged_value_to_percentage(SPEED_RANGE, self.info.primary_value.value) @property - def speed_count(self) -> Optional[int]: + def speed_count(self) -> int: """Return the number of speeds the fan supports.""" return int_states_in_range(SPEED_RANGE)