From 1303dd12e77ecb175b8b5acc19c2d7d92970ef65 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Tue, 21 Mar 2023 15:21:56 +0100 Subject: [PATCH] Improve type hints in zha fan (#90042) --- homeassistant/components/zha/fan.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/zha/fan.py b/homeassistant/components/zha/fan.py index 13d63808b61..5153d3c4567 100644 --- a/homeassistant/components/zha/fan.py +++ b/homeassistant/components/zha/fan.py @@ -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: