Use shorthand attributes in Tado (#99886)

This commit is contained in:
Joost Lekkerkerker 2023-09-08 01:15:49 +02:00 committed by GitHub
parent 56f05bee91
commit a3d6c6192e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 73 deletions

View File

@ -219,6 +219,8 @@ class TadoClimate(TadoZoneEntity, ClimateEntity):
_attr_temperature_unit = UnitOfTemperature.CELSIUS
_attr_name = None
_attr_translation_key = DOMAIN
_available = False
def __init__(
self,
@ -245,22 +247,22 @@ class TadoClimate(TadoZoneEntity, ClimateEntity):
self.zone_type = zone_type
self._attr_unique_id = f"{zone_type} {zone_id} {tado.home_id}"
self._attr_temperature_unit = UnitOfTemperature.CELSIUS
self._attr_translation_key = DOMAIN
self._device_info = device_info
self._device_id = self._device_info["shortSerialNo"]
self._ac_device = zone_type == TYPE_AIR_CONDITIONING
self._supported_hvac_modes = supported_hvac_modes
self._supported_fan_modes = supported_fan_modes
self._attr_hvac_modes = supported_hvac_modes
self._attr_fan_modes = supported_fan_modes
self._attr_supported_features = support_flags
self._available = False
self._cur_temp = None
self._cur_humidity = None
if self.supported_features & ClimateEntityFeature.SWING_MODE:
self._attr_swing_modes = [
TADO_TO_HA_SWING_MODE_MAP[TADO_SWING_ON],
TADO_TO_HA_SWING_MODE_MAP[TADO_SWING_OFF],
]
self._heat_min_temp = heat_min_temp
self._heat_max_temp = heat_max_temp
@ -324,14 +326,6 @@ class TadoClimate(TadoZoneEntity, ClimateEntity):
"""
return TADO_TO_HA_HVAC_MODE_MAP.get(self._current_tado_hvac_mode, HVACMode.OFF)
@property
def hvac_modes(self) -> list[HVACMode]:
"""Return the list of available hvac operation modes.
Need to be a subset of HVAC_MODES.
"""
return self._supported_hvac_modes
@property
def hvac_action(self) -> HVACAction:
"""Return the current running hvac operation if supported.
@ -349,11 +343,6 @@ class TadoClimate(TadoZoneEntity, ClimateEntity):
return TADO_TO_HA_FAN_MODE_MAP.get(self._current_tado_fan_speed, FAN_AUTO)
return None
@property
def fan_modes(self):
"""List of available fan modes."""
return self._supported_fan_modes
def set_fan_mode(self, fan_mode: str) -> None:
"""Turn fan on/off."""
self._control_hvac(fan_mode=HA_TO_TADO_FAN_MODE_MAP[fan_mode])
@ -474,16 +463,6 @@ class TadoClimate(TadoZoneEntity, ClimateEntity):
"""Active swing mode for the device."""
return TADO_TO_HA_SWING_MODE_MAP[self._current_tado_swing_mode]
@property
def swing_modes(self):
"""Swing modes for the device."""
if self.supported_features & ClimateEntityFeature.SWING_MODE:
return [
TADO_TO_HA_SWING_MODE_MAP[TADO_SWING_ON],
TADO_TO_HA_SWING_MODE_MAP[TADO_SWING_OFF],
]
return None
@property
def extra_state_attributes(self):
"""Return temperature offset."""

View File

@ -17,18 +17,14 @@ class TadoDeviceEntity(Entity):
self._device_info = device_info
self.device_name = device_info["serialNo"]
self.device_id = device_info["shortSerialNo"]
@property
def device_info(self) -> DeviceInfo:
"""Return the device_info of the device."""
return DeviceInfo(
self._attr_device_info = DeviceInfo(
configuration_url=f"https://app.tado.com/en/main/settings/rooms-and-devices/device/{self.device_name}",
identifiers={(DOMAIN, self.device_id)},
name=self.device_name,
manufacturer=DEFAULT_NAME,
sw_version=self._device_info["currentFwVersion"],
model=self._device_info["deviceType"],
via_device=(DOMAIN, self._device_info["serialNo"]),
sw_version=device_info["currentFwVersion"],
model=device_info["deviceType"],
via_device=(DOMAIN, device_info["serialNo"]),
)
@ -43,16 +39,12 @@ class TadoHomeEntity(Entity):
super().__init__()
self.home_name = tado.home_name
self.home_id = tado.home_id
@property
def device_info(self) -> DeviceInfo:
"""Return the device_info of the device."""
return DeviceInfo(
self._attr_device_info = DeviceInfo(
configuration_url="https://app.tado.com",
identifiers={(DOMAIN, self.home_id)},
identifiers={(DOMAIN, tado.home_id)},
manufacturer=DEFAULT_NAME,
model=TADO_HOME,
name=self.home_name,
name=tado.home_name,
)
@ -65,20 +57,13 @@ class TadoZoneEntity(Entity):
def __init__(self, zone_name, home_id, zone_id):
"""Initialize a Tado zone."""
super().__init__()
self._device_zone_id = f"{home_id}_{zone_id}"
self.zone_name = zone_name
self.zone_id = zone_id
@property
def device_info(self) -> DeviceInfo:
"""Return the device_info of the device."""
return DeviceInfo(
configuration_url=(
f"https://app.tado.com/en/main/home/zoneV2/{self.zone_id}"
),
identifiers={(DOMAIN, self._device_zone_id)},
name=self.zone_name,
self._attr_device_info = DeviceInfo(
configuration_url=(f"https://app.tado.com/en/main/home/zoneV2/{zone_id}"),
identifiers={(DOMAIN, f"{home_id}_{zone_id}")},
name=zone_name,
manufacturer=DEFAULT_NAME,
model=TADO_ZONE,
suggested_area=self.zone_name,
suggested_area=zone_name,
)

View File

@ -120,6 +120,8 @@ class TadoWaterHeater(TadoZoneEntity, WaterHeaterEntity):
"""Representation of a Tado water heater."""
_attr_name = None
_attr_operation_list = OPERATION_MODES
_attr_temperature_unit = UnitOfTemperature.CELSIUS
def __init__(
self,
@ -136,7 +138,7 @@ class TadoWaterHeater(TadoZoneEntity, WaterHeaterEntity):
super().__init__(zone_name, tado.home_id, zone_id)
self.zone_id = zone_id
self._unique_id = f"{zone_id} {tado.home_id}"
self._attr_unique_id = f"{zone_id} {tado.home_id}"
self._device_is_active = False
@ -168,11 +170,6 @@ class TadoWaterHeater(TadoZoneEntity, WaterHeaterEntity):
)
self._async_update_data()
@property
def unique_id(self):
"""Return the unique id."""
return self._unique_id
@property
def current_operation(self):
"""Return current readable operation mode."""
@ -188,16 +185,6 @@ class TadoWaterHeater(TadoZoneEntity, WaterHeaterEntity):
"""Return true if away mode is on."""
return self._tado_zone_data.is_away
@property
def operation_list(self):
"""Return the list of available operation modes (readable)."""
return OPERATION_MODES
@property
def temperature_unit(self):
"""Return the unit of measurement used by the platform."""
return UnitOfTemperature.CELSIUS
@property
def min_temp(self):
"""Return the minimum temperature."""