From fd1ddbd93df4486c8f272420501ea2d9bbe67908 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Tue, 20 May 2025 09:31:42 +0200 Subject: [PATCH] Improve type hints in blebox climate (#145282) --- homeassistant/components/blebox/climate.py | 17 +++++++++-------- tests/components/blebox/test_climate.py | 2 +- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/homeassistant/components/blebox/climate.py b/homeassistant/components/blebox/climate.py index dbf4a326990..2d1f6c5ae9e 100644 --- a/homeassistant/components/blebox/climate.py +++ b/homeassistant/components/blebox/climate.py @@ -21,7 +21,6 @@ from .entity import BleBoxEntity SCAN_INTERVAL = timedelta(seconds=5) BLEBOX_TO_HVACMODE = { - None: None, 0: HVACMode.OFF, 1: HVACMode.HEAT, 2: HVACMode.COOL, @@ -59,12 +58,14 @@ class BleBoxClimateEntity(BleBoxEntity[blebox_uniapi.climate.Climate], ClimateEn _attr_temperature_unit = UnitOfTemperature.CELSIUS @property - def hvac_modes(self): + def hvac_modes(self) -> list[HVACMode]: """Return list of supported HVAC modes.""" + if self._feature.mode is None: + return [HVACMode.OFF] return [HVACMode.OFF, BLEBOX_TO_HVACMODE[self._feature.mode]] @property - def hvac_mode(self): + def hvac_mode(self) -> HVACMode | None: """Return the desired HVAC mode.""" if self._feature.is_on is None: return None @@ -75,7 +76,7 @@ class BleBoxClimateEntity(BleBoxEntity[blebox_uniapi.climate.Climate], ClimateEn return HVACMode.HEAT if self._feature.is_on else HVACMode.OFF @property - def hvac_action(self): + def hvac_action(self) -> HVACAction | None: """Return the actual current HVAC action.""" if self._feature.hvac_action is not None: if not self._feature.is_on: @@ -88,22 +89,22 @@ class BleBoxClimateEntity(BleBoxEntity[blebox_uniapi.climate.Climate], ClimateEn return HVACAction.HEATING if self._feature.is_heating else HVACAction.IDLE @property - def max_temp(self): + def max_temp(self) -> float: """Return the maximum temperature supported.""" return self._feature.max_temp @property - def min_temp(self): + def min_temp(self) -> float: """Return the maximum temperature supported.""" return self._feature.min_temp @property - def current_temperature(self): + def current_temperature(self) -> float | None: """Return the current temperature.""" return self._feature.current @property - def target_temperature(self): + def target_temperature(self) -> float | None: """Return the desired thermostat temperature.""" return self._feature.desired diff --git a/tests/components/blebox/test_climate.py b/tests/components/blebox/test_climate.py index e402a3d5fbd..9da2d9a8a68 100644 --- a/tests/components/blebox/test_climate.py +++ b/tests/components/blebox/test_climate.py @@ -93,7 +93,7 @@ async def test_init( supported_features = state.attributes[ATTR_SUPPORTED_FEATURES] assert supported_features & ClimateEntityFeature.TARGET_TEMPERATURE - assert state.attributes[ATTR_HVAC_MODES] == [HVACMode.OFF, None] + assert state.attributes[ATTR_HVAC_MODES] == [HVACMode.OFF] assert ATTR_DEVICE_CLASS not in state.attributes assert ATTR_HVAC_MODE not in state.attributes