From 46affe5c824b9f0dae6d44370076c0ae4f7e9170 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Tue, 30 Aug 2022 21:46:50 +0200 Subject: [PATCH] Adjust type hints in generic_thermostat (#77490) --- .../components/generic_thermostat/climate.py | 41 ++++++------------- 1 file changed, 12 insertions(+), 29 deletions(-) diff --git a/homeassistant/components/generic_thermostat/climate.py b/homeassistant/components/generic_thermostat/climate.py index 9dd49dd851d..f095037d7f7 100644 --- a/homeassistant/components/generic_thermostat/climate.py +++ b/homeassistant/components/generic_thermostat/climate.py @@ -189,7 +189,7 @@ class GenericThermostat(ClimateEntity, RestoreEntity): unique_id, ): """Initialize the thermostat.""" - self._name = name + self._attr_name = name self.heater_entity_id = heater_entity_id self.sensor_entity_id = sensor_entity_id self.ac_mode = ac_mode @@ -202,9 +202,9 @@ class GenericThermostat(ClimateEntity, RestoreEntity): self._temp_precision = precision self._temp_target_temperature_step = target_temperature_step if self.ac_mode: - self._hvac_list = [HVACMode.COOL, HVACMode.OFF] + self._attr_hvac_modes = [HVACMode.COOL, HVACMode.OFF] else: - self._hvac_list = [HVACMode.HEAT, HVACMode.OFF] + self._attr_hvac_modes = [HVACMode.HEAT, HVACMode.OFF] self._active = False self._cur_temp = None self._temp_lock = asyncio.Lock() @@ -212,8 +212,8 @@ class GenericThermostat(ClimateEntity, RestoreEntity): self._max_temp = max_temp self._attr_preset_mode = PRESET_NONE self._target_temp = target_temp - self._unit = unit - self._unique_id = unique_id + self._attr_temperature_unit = unit + self._attr_unique_id = unique_id self._attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE if len(presets): self._attr_supported_features |= ClimateEntityFeature.PRESET_MODE @@ -222,7 +222,7 @@ class GenericThermostat(ClimateEntity, RestoreEntity): self._attr_preset_modes = [PRESET_NONE] self._presets = presets - async def async_added_to_hass(self): + async def async_added_to_hass(self) -> None: """Run when entity about to be added.""" await super().async_added_to_hass() @@ -283,7 +283,10 @@ class GenericThermostat(ClimateEntity, RestoreEntity): ) else: self._target_temp = float(old_state.attributes[ATTR_TEMPERATURE]) - if old_state.attributes.get(ATTR_PRESET_MODE) in self._attr_preset_modes: + if ( + self.preset_modes + and old_state.attributes.get(ATTR_PRESET_MODE) in self.preset_modes + ): self._attr_preset_mode = old_state.attributes.get(ATTR_PRESET_MODE) if not self._hvac_mode and old_state.state: self._hvac_mode = old_state.state @@ -303,16 +306,6 @@ class GenericThermostat(ClimateEntity, RestoreEntity): if not self._hvac_mode: self._hvac_mode = HVACMode.OFF - @property - def name(self): - """Return the name of the thermostat.""" - return self._name - - @property - def unique_id(self): - """Return the unique id of this thermostat.""" - return self._unique_id - @property def precision(self): """Return the precision of the system.""" @@ -328,11 +321,6 @@ class GenericThermostat(ClimateEntity, RestoreEntity): # if a target_temperature_step is not defined, fallback to equal the precision return self.precision - @property - def temperature_unit(self): - """Return the unit of measurement.""" - return self._unit - @property def current_temperature(self): """Return the sensor temperature.""" @@ -362,11 +350,6 @@ class GenericThermostat(ClimateEntity, RestoreEntity): """Return the temperature we try to reach.""" return self._target_temp - @property - def hvac_modes(self): - """List of available operation modes.""" - return self._hvac_list - async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None: """Set hvac mode.""" if hvac_mode == HVACMode.HEAT: @@ -540,9 +523,9 @@ class GenericThermostat(ClimateEntity, RestoreEntity): async def async_set_preset_mode(self, preset_mode: str) -> None: """Set new preset mode.""" - if preset_mode not in (self._attr_preset_modes or []): + if preset_mode not in (self.preset_modes or []): raise ValueError( - f"Got unsupported preset_mode {preset_mode}. Must be one of {self._attr_preset_modes}" + f"Got unsupported preset_mode {preset_mode}. Must be one of {self.preset_modes}" ) if preset_mode == self._attr_preset_mode: # I don't think we need to call async_write_ha_state if we didn't change the state