Add entity translations to Aseko (#98117)

This commit is contained in:
Joost Lekkerkerker 2023-08-14 12:52:27 +02:00 committed by GitHub
parent 9ce033daeb
commit 11b1a42a1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 9 deletions

View File

@ -37,19 +37,18 @@ class AsekoBinarySensorEntityDescription(
UNIT_BINARY_SENSORS: tuple[AsekoBinarySensorEntityDescription, ...] = ( UNIT_BINARY_SENSORS: tuple[AsekoBinarySensorEntityDescription, ...] = (
AsekoBinarySensorEntityDescription( AsekoBinarySensorEntityDescription(
key="water_flow", key="water_flow",
name="Water Flow", translation_key="water_flow",
icon="mdi:waves-arrow-right", icon="mdi:waves-arrow-right",
value_fn=lambda unit: unit.water_flow, value_fn=lambda unit: unit.water_flow,
), ),
AsekoBinarySensorEntityDescription( AsekoBinarySensorEntityDescription(
key="has_alarm", key="has_alarm",
name="Alarm", translation_key="alarm",
value_fn=lambda unit: unit.has_alarm, value_fn=lambda unit: unit.has_alarm,
device_class=BinarySensorDeviceClass.SAFETY, device_class=BinarySensorDeviceClass.SAFETY,
), ),
AsekoBinarySensorEntityDescription( AsekoBinarySensorEntityDescription(
key="has_error", key="has_error",
name="Error",
value_fn=lambda unit: unit.has_error, value_fn=lambda unit: unit.has_error,
device_class=BinarySensorDeviceClass.PROBLEM, device_class=BinarySensorDeviceClass.PROBLEM,
), ),

View File

@ -11,6 +11,8 @@ from .coordinator import AsekoDataUpdateCoordinator
class AsekoEntity(CoordinatorEntity[AsekoDataUpdateCoordinator]): class AsekoEntity(CoordinatorEntity[AsekoDataUpdateCoordinator]):
"""Representation of an aseko entity.""" """Representation of an aseko entity."""
_attr_has_entity_name = True
def __init__(self, unit: Unit, coordinator: AsekoDataUpdateCoordinator) -> None: def __init__(self, unit: Unit, coordinator: AsekoDataUpdateCoordinator) -> None:
"""Initialize the aseko entity.""" """Initialize the aseko entity."""
super().__init__(coordinator) super().__init__(coordinator)

View File

@ -45,13 +45,16 @@ class VariableSensorEntity(AsekoEntity, SensorEntity):
super().__init__(unit, coordinator) super().__init__(unit, coordinator)
self._variable = variable self._variable = variable
variable_name = { translation_key = {
"Air temp.": "Air Temperature", "Air temp.": "air_temperature",
"Cl free": "Free Chlorine", "Cl free": "free_chlorine",
"Water temp.": "Water Temperature", "Water temp.": "water_temperature",
}.get(self._variable.name, self._variable.name) }.get(self._variable.name)
if translation_key is not None:
self._attr_translation_key = translation_key
else:
self._attr_name = self._variable.name
self._attr_name = f"{self._device_name} {variable_name}"
self._attr_unique_id = f"{self._unit.serial_number}{self._variable.type}" self._attr_unique_id = f"{self._unit.serial_number}{self._variable.type}"
self._attr_native_unit_of_measurement = self._variable.unit self._attr_native_unit_of_measurement = self._variable.unit

View File

@ -16,5 +16,26 @@
"abort": { "abort": {
"already_configured": "[%key:common::config_flow::abort::already_configured_account%]" "already_configured": "[%key:common::config_flow::abort::already_configured_account%]"
} }
},
"entity": {
"binary_sensor": {
"water_flow": {
"name": "Water flow"
},
"alarm": {
"name": "Alarm"
}
},
"sensor": {
"air_temperature": {
"name": "Air temperature"
},
"free_chlorine": {
"name": "Free chlorine"
},
"water_temperature": {
"name": "Water temperature"
}
}
} }
} }