Add icon translations to Balboa (#111343)

This commit is contained in:
Joost Lekkerkerker 2024-02-25 10:40:44 +01:00 committed by GitHub
parent 496339773b
commit cb6cf3bedc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 11 deletions

View File

@ -38,7 +38,6 @@ class BalboaBinarySensorEntityDescriptionMixin:
"""Mixin for required keys."""
is_on_fn: Callable[[SpaClient], bool]
on_off_icons: tuple[str, str]
@dataclass(frozen=True)
@ -48,21 +47,18 @@ class BalboaBinarySensorEntityDescription(
"""A class that describes Balboa binary sensor entities."""
FILTER_CYCLE_ICONS = ("mdi:sync", "mdi:sync-off")
BINARY_SENSOR_DESCRIPTIONS = (
BalboaBinarySensorEntityDescription(
key="Filter1",
translation_key="filter_1",
device_class=BinarySensorDeviceClass.RUNNING,
is_on_fn=lambda spa: spa.filter_cycle_1_running,
on_off_icons=FILTER_CYCLE_ICONS,
),
BalboaBinarySensorEntityDescription(
key="Filter2",
translation_key="filter_2",
device_class=BinarySensorDeviceClass.RUNNING,
is_on_fn=lambda spa: spa.filter_cycle_2_running,
on_off_icons=FILTER_CYCLE_ICONS,
),
)
CIRCULATION_PUMP_DESCRIPTION = BalboaBinarySensorEntityDescription(
@ -70,7 +66,6 @@ CIRCULATION_PUMP_DESCRIPTION = BalboaBinarySensorEntityDescription(
translation_key="circ_pump",
device_class=BinarySensorDeviceClass.RUNNING,
is_on_fn=lambda spa: (pump := spa.circulation_pump) is not None and pump.state > 0,
on_off_icons=("mdi:pump", "mdi:pump-off"),
)
@ -90,9 +85,3 @@ class BalboaBinarySensorEntity(BalboaEntity, BinarySensorEntity):
def is_on(self) -> bool:
"""Return true if the binary sensor is on."""
return self.entity_description.is_on_fn(self._client)
@property
def icon(self) -> str | None:
"""Return the icon to use in the frontend, if any."""
icons = self.entity_description.on_off_icons
return icons[0] if self.is_on else icons[1]

View File

@ -0,0 +1,24 @@
{
"entity": {
"binary_sensor": {
"filter_1": {
"default": "mdi:sync-off",
"state": {
"on": "mdi:sync"
}
},
"filter_2": {
"default": "mdi:sync-off",
"state": {
"on": "mdi:sync"
}
},
"circ_pump": {
"default": "mdi:pump-off",
"state": {
"on": "mdi:pump"
}
}
}
}
}