Fix typing of fan speed count and steps (#46790)

This commit is contained in:
J. Nick Koston 2021-02-19 19:57:21 -10:00 committed by GitHub
parent 0e9148e239
commit 3e334a4950
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 16 additions and 14 deletions

View file

@ -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)

View file

@ -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

View file

@ -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)

View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -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)

View file

@ -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

View file

@ -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)