Improve type hints in zha fan (#90042)

This commit is contained in:
epenet 2023-03-21 15:21:56 +01:00 committed by GitHub
parent 6f88fe93ef
commit 1303dd12e7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -278,10 +278,8 @@ class IkeaFan(BaseFan, ZhaEntity):
"""Return the number of speeds the fan supports."""
return int_states_in_range(IKEA_SPEED_RANGE)
async def async_set_percentage(self, percentage: int | None) -> None:
"""Set the speed percenage of the fan."""
if percentage is None:
percentage = 0
async def async_set_percentage(self, percentage: int) -> None:
"""Set the speed percentage of the fan."""
fan_mode = math.ceil(percentage_to_ranged_value(IKEA_SPEED_RANGE, percentage))
await self._async_set_fan_mode(fan_mode)
@ -311,12 +309,17 @@ class IkeaFan(BaseFan, ZhaEntity):
"""Return the current preset mode."""
return IKEA_PRESET_MODES_TO_NAME.get(self._fan_channel.fan_mode)
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 = (100 / self.speed_count) * IKEA_NAME_TO_PRESET_MODE[
PRESET_MODE_AUTO
]
percentage = int(
(100 / self.speed_count) * IKEA_NAME_TO_PRESET_MODE[PRESET_MODE_AUTO]
)
await self.async_set_percentage(percentage)
async def async_turn_off(self, **kwargs: Any) -> None: