Adjust type hints in generic_thermostat (#77490)
This commit is contained in:
parent
4655ed995e
commit
46affe5c82
1 changed files with 12 additions and 29 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue