Add entity translations to Tado (#96226)
This commit is contained in:
parent
995c4d8ac1
commit
26152adb23
7 changed files with 60 additions and 36 deletions
|
@ -50,31 +50,28 @@ class TadoBinarySensorEntityDescription(
|
|||
|
||||
BATTERY_STATE_ENTITY_DESCRIPTION = TadoBinarySensorEntityDescription(
|
||||
key="battery state",
|
||||
name="Battery state",
|
||||
state_fn=lambda data: data["batteryState"] == "LOW",
|
||||
device_class=BinarySensorDeviceClass.BATTERY,
|
||||
)
|
||||
CONNECTION_STATE_ENTITY_DESCRIPTION = TadoBinarySensorEntityDescription(
|
||||
key="connection state",
|
||||
name="Connection state",
|
||||
translation_key="connection_state",
|
||||
state_fn=lambda data: data.get("connectionState", {}).get("value", False),
|
||||
device_class=BinarySensorDeviceClass.CONNECTIVITY,
|
||||
)
|
||||
POWER_ENTITY_DESCRIPTION = TadoBinarySensorEntityDescription(
|
||||
key="power",
|
||||
name="Power",
|
||||
state_fn=lambda data: data.power == "ON",
|
||||
device_class=BinarySensorDeviceClass.POWER,
|
||||
)
|
||||
LINK_ENTITY_DESCRIPTION = TadoBinarySensorEntityDescription(
|
||||
key="link",
|
||||
name="Link",
|
||||
state_fn=lambda data: data.link == "ONLINE",
|
||||
device_class=BinarySensorDeviceClass.CONNECTIVITY,
|
||||
)
|
||||
OVERLAY_ENTITY_DESCRIPTION = TadoBinarySensorEntityDescription(
|
||||
key="overlay",
|
||||
name="Overlay",
|
||||
translation_key="overlay",
|
||||
state_fn=lambda data: data.overlay_active,
|
||||
attributes_fn=lambda data: {"termination": data.overlay_termination_type}
|
||||
if data.overlay_active
|
||||
|
@ -83,14 +80,13 @@ OVERLAY_ENTITY_DESCRIPTION = TadoBinarySensorEntityDescription(
|
|||
)
|
||||
OPEN_WINDOW_ENTITY_DESCRIPTION = TadoBinarySensorEntityDescription(
|
||||
key="open window",
|
||||
name="Open window",
|
||||
state_fn=lambda data: bool(data.open_window or data.open_window_detected),
|
||||
attributes_fn=lambda data: data.open_window_attr,
|
||||
device_class=BinarySensorDeviceClass.WINDOW,
|
||||
)
|
||||
EARLY_START_ENTITY_DESCRIPTION = TadoBinarySensorEntityDescription(
|
||||
key="early start",
|
||||
name="Early start",
|
||||
translation_key="early_start",
|
||||
state_fn=lambda data: data.preparation,
|
||||
device_class=BinarySensorDeviceClass.POWER,
|
||||
)
|
||||
|
@ -173,8 +169,6 @@ class TadoDeviceBinarySensor(TadoDeviceEntity, BinarySensorEntity):
|
|||
|
||||
entity_description: TadoBinarySensorEntityDescription
|
||||
|
||||
_attr_has_entity_name = True
|
||||
|
||||
def __init__(
|
||||
self, tado, device_info, entity_description: TadoBinarySensorEntityDescription
|
||||
) -> None:
|
||||
|
@ -227,8 +221,6 @@ class TadoZoneBinarySensor(TadoZoneEntity, BinarySensorEntity):
|
|||
|
||||
entity_description: TadoBinarySensorEntityDescription
|
||||
|
||||
_attr_has_entity_name = True
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
tado,
|
||||
|
|
|
@ -218,6 +218,7 @@ class TadoClimate(TadoZoneEntity, ClimateEntity):
|
|||
"""Representation of a Tado climate entity."""
|
||||
|
||||
_attr_temperature_unit = UnitOfTemperature.CELSIUS
|
||||
_attr_name = None
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
|
@ -244,7 +245,6 @@ class TadoClimate(TadoZoneEntity, ClimateEntity):
|
|||
self.zone_type = zone_type
|
||||
|
||||
self._attr_unique_id = f"{zone_type} {zone_id} {tado.home_id}"
|
||||
self._attr_name = zone_name
|
||||
self._attr_temperature_unit = UnitOfTemperature.CELSIUS
|
||||
|
||||
self._attr_translation_key = DOMAIN
|
||||
|
|
|
@ -8,6 +8,7 @@ class TadoDeviceEntity(Entity):
|
|||
"""Base implementation for Tado device."""
|
||||
|
||||
_attr_should_poll = False
|
||||
_attr_has_entity_name = True
|
||||
|
||||
def __init__(self, device_info):
|
||||
"""Initialize a Tado device."""
|
||||
|
@ -34,6 +35,7 @@ class TadoHomeEntity(Entity):
|
|||
"""Base implementation for Tado home."""
|
||||
|
||||
_attr_should_poll = False
|
||||
_attr_has_entity_name = True
|
||||
|
||||
def __init__(self, tado):
|
||||
"""Initialize a Tado home."""
|
||||
|
@ -56,6 +58,7 @@ class TadoHomeEntity(Entity):
|
|||
class TadoZoneEntity(Entity):
|
||||
"""Base implementation for Tado zone."""
|
||||
|
||||
_attr_has_entity_name = True
|
||||
_attr_should_poll = False
|
||||
|
||||
def __init__(self, zone_name, home_id, zone_id):
|
||||
|
|
|
@ -55,7 +55,7 @@ class TadoSensorEntityDescription(
|
|||
HOME_SENSORS = [
|
||||
TadoSensorEntityDescription(
|
||||
key="outdoor temperature",
|
||||
name="Outdoor temperature",
|
||||
translation_key="outdoor_temperature",
|
||||
state_fn=lambda data: data["outsideTemperature"]["celsius"],
|
||||
attributes_fn=lambda data: {
|
||||
"time": data["outsideTemperature"]["timestamp"],
|
||||
|
@ -67,7 +67,7 @@ HOME_SENSORS = [
|
|||
),
|
||||
TadoSensorEntityDescription(
|
||||
key="solar percentage",
|
||||
name="Solar percentage",
|
||||
translation_key="solar_percentage",
|
||||
state_fn=lambda data: data["solarIntensity"]["percentage"],
|
||||
attributes_fn=lambda data: {
|
||||
"time": data["solarIntensity"]["timestamp"],
|
||||
|
@ -78,28 +78,28 @@ HOME_SENSORS = [
|
|||
),
|
||||
TadoSensorEntityDescription(
|
||||
key="weather condition",
|
||||
name="Weather condition",
|
||||
translation_key="weather_condition",
|
||||
state_fn=lambda data: format_condition(data["weatherState"]["value"]),
|
||||
attributes_fn=lambda data: {"time": data["weatherState"]["timestamp"]},
|
||||
data_category=SENSOR_DATA_CATEGORY_WEATHER,
|
||||
),
|
||||
TadoSensorEntityDescription(
|
||||
key="tado mode",
|
||||
name="Tado mode",
|
||||
translation_key="tado_mode",
|
||||
# pylint: disable=unnecessary-lambda
|
||||
state_fn=lambda data: get_tado_mode(data),
|
||||
data_category=SENSOR_DATA_CATEGORY_GEOFENCE,
|
||||
),
|
||||
TadoSensorEntityDescription(
|
||||
key="geofencing mode",
|
||||
name="Geofencing mode",
|
||||
translation_key="geofencing_mode",
|
||||
# pylint: disable=unnecessary-lambda
|
||||
state_fn=lambda data: get_geofencing_mode(data),
|
||||
data_category=SENSOR_DATA_CATEGORY_GEOFENCE,
|
||||
),
|
||||
TadoSensorEntityDescription(
|
||||
key="automatic geofencing",
|
||||
name="Automatic geofencing",
|
||||
translation_key="automatic_geofencing",
|
||||
# pylint: disable=unnecessary-lambda
|
||||
state_fn=lambda data: get_automatic_geofencing(data),
|
||||
data_category=SENSOR_DATA_CATEGORY_GEOFENCE,
|
||||
|
@ -108,7 +108,6 @@ HOME_SENSORS = [
|
|||
|
||||
TEMPERATURE_ENTITY_DESCRIPTION = TadoSensorEntityDescription(
|
||||
key="temperature",
|
||||
name="Temperature",
|
||||
state_fn=lambda data: data.current_temp,
|
||||
attributes_fn=lambda data: {
|
||||
"time": data.current_temp_timestamp,
|
||||
|
@ -120,7 +119,6 @@ TEMPERATURE_ENTITY_DESCRIPTION = TadoSensorEntityDescription(
|
|||
)
|
||||
HUMIDITY_ENTITY_DESCRIPTION = TadoSensorEntityDescription(
|
||||
key="humidity",
|
||||
name="Humidity",
|
||||
state_fn=lambda data: data.current_humidity,
|
||||
attributes_fn=lambda data: {"time": data.current_humidity_timestamp},
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
|
@ -129,12 +127,12 @@ HUMIDITY_ENTITY_DESCRIPTION = TadoSensorEntityDescription(
|
|||
)
|
||||
TADO_MODE_ENTITY_DESCRIPTION = TadoSensorEntityDescription(
|
||||
key="tado mode",
|
||||
name="Tado mode",
|
||||
translation_key="tado_mode",
|
||||
state_fn=lambda data: data.tado_mode,
|
||||
)
|
||||
HEATING_ENTITY_DESCRIPTION = TadoSensorEntityDescription(
|
||||
key="heating",
|
||||
name="Heating",
|
||||
translation_key="heating",
|
||||
state_fn=lambda data: data.heating_power_percentage,
|
||||
attributes_fn=lambda data: {"time": data.heating_power_timestamp},
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
|
@ -142,6 +140,7 @@ HEATING_ENTITY_DESCRIPTION = TadoSensorEntityDescription(
|
|||
)
|
||||
AC_ENTITY_DESCRIPTION = TadoSensorEntityDescription(
|
||||
key="ac",
|
||||
translation_key="ac",
|
||||
name="AC",
|
||||
state_fn=lambda data: data.ac_power,
|
||||
attributes_fn=lambda data: {"time": data.ac_power_timestamp},
|
||||
|
@ -244,8 +243,6 @@ class TadoHomeSensor(TadoHomeEntity, SensorEntity):
|
|||
|
||||
entity_description: TadoSensorEntityDescription
|
||||
|
||||
_attr_has_entity_name = True
|
||||
|
||||
def __init__(self, tado, entity_description: TadoSensorEntityDescription) -> None:
|
||||
"""Initialize of the Tado Sensor."""
|
||||
self.entity_description = entity_description
|
||||
|
@ -298,8 +295,6 @@ class TadoZoneSensor(TadoZoneEntity, SensorEntity):
|
|||
|
||||
entity_description: TadoSensorEntityDescription
|
||||
|
||||
_attr_has_entity_name = True
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
tado,
|
||||
|
|
|
@ -31,6 +31,17 @@
|
|||
}
|
||||
},
|
||||
"entity": {
|
||||
"binary_sensor": {
|
||||
"connection_state": {
|
||||
"name": "Connection state"
|
||||
},
|
||||
"overlay": {
|
||||
"name": "Overlay"
|
||||
},
|
||||
"early_start": {
|
||||
"name": "Early start"
|
||||
}
|
||||
},
|
||||
"climate": {
|
||||
"tado": {
|
||||
"state_attributes": {
|
||||
|
@ -41,6 +52,32 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"sensor": {
|
||||
"outdoor_temperature": {
|
||||
"name": "Outdoor temperature"
|
||||
},
|
||||
"solar_percentage": {
|
||||
"name": "Solar percentage"
|
||||
},
|
||||
"weather_condition": {
|
||||
"name": "Weather condition"
|
||||
},
|
||||
"tado_mode": {
|
||||
"name": "Tado mode"
|
||||
},
|
||||
"geofencing_mode": {
|
||||
"name": "Geofencing mode"
|
||||
},
|
||||
"automatic_geofencing": {
|
||||
"name": "Automatic geofencing"
|
||||
},
|
||||
"heating": {
|
||||
"name": "Heating"
|
||||
},
|
||||
"ac": {
|
||||
"name": "AC"
|
||||
}
|
||||
}
|
||||
},
|
||||
"services": {
|
||||
|
|
|
@ -119,6 +119,8 @@ def create_water_heater_entity(tado, name: str, zone_id: int, zone: str):
|
|||
class TadoWaterHeater(TadoZoneEntity, WaterHeaterEntity):
|
||||
"""Representation of a Tado water heater."""
|
||||
|
||||
_attr_name = None
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
tado,
|
||||
|
@ -166,11 +168,6 @@ class TadoWaterHeater(TadoZoneEntity, WaterHeaterEntity):
|
|||
)
|
||||
self._async_update_data()
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the entity."""
|
||||
return self.zone_name
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
"""Return the unique id."""
|
||||
|
|
|
@ -13,13 +13,13 @@ async def test_air_con_create_binary_sensors(hass: HomeAssistant) -> None:
|
|||
state = hass.states.get("binary_sensor.air_conditioning_power")
|
||||
assert state.state == STATE_ON
|
||||
|
||||
state = hass.states.get("binary_sensor.air_conditioning_link")
|
||||
state = hass.states.get("binary_sensor.air_conditioning_connectivity")
|
||||
assert state.state == STATE_ON
|
||||
|
||||
state = hass.states.get("binary_sensor.air_conditioning_overlay")
|
||||
assert state.state == STATE_ON
|
||||
|
||||
state = hass.states.get("binary_sensor.air_conditioning_open_window")
|
||||
state = hass.states.get("binary_sensor.air_conditioning_window")
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
|
||||
|
@ -31,7 +31,7 @@ async def test_heater_create_binary_sensors(hass: HomeAssistant) -> None:
|
|||
state = hass.states.get("binary_sensor.baseboard_heater_power")
|
||||
assert state.state == STATE_ON
|
||||
|
||||
state = hass.states.get("binary_sensor.baseboard_heater_link")
|
||||
state = hass.states.get("binary_sensor.baseboard_heater_connectivity")
|
||||
assert state.state == STATE_ON
|
||||
|
||||
state = hass.states.get("binary_sensor.baseboard_heater_early_start")
|
||||
|
@ -40,7 +40,7 @@ async def test_heater_create_binary_sensors(hass: HomeAssistant) -> None:
|
|||
state = hass.states.get("binary_sensor.baseboard_heater_overlay")
|
||||
assert state.state == STATE_ON
|
||||
|
||||
state = hass.states.get("binary_sensor.baseboard_heater_open_window")
|
||||
state = hass.states.get("binary_sensor.baseboard_heater_window")
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
|
||||
|
@ -49,7 +49,7 @@ async def test_water_heater_create_binary_sensors(hass: HomeAssistant) -> None:
|
|||
|
||||
await async_init_integration(hass)
|
||||
|
||||
state = hass.states.get("binary_sensor.water_heater_link")
|
||||
state = hass.states.get("binary_sensor.water_heater_connectivity")
|
||||
assert state.state == STATE_ON
|
||||
|
||||
state = hass.states.get("binary_sensor.water_heater_overlay")
|
||||
|
|
Loading…
Add table
Reference in a new issue