Add entity translations to Balboa (#104543)
This commit is contained in:
parent
e3599bc26f
commit
2e1c722303
6 changed files with 24 additions and 17 deletions
|
@ -47,31 +47,27 @@ class BalboaBinarySensorEntityDescription(
|
|||
):
|
||||
"""A class that describes Balboa binary sensor entities."""
|
||||
|
||||
# BalboaBinarySensorEntity does not support UNDEFINED or None,
|
||||
# restrict the type to str.
|
||||
name: str = ""
|
||||
|
||||
|
||||
FILTER_CYCLE_ICONS = ("mdi:sync", "mdi:sync-off")
|
||||
BINARY_SENSOR_DESCRIPTIONS = (
|
||||
BalboaBinarySensorEntityDescription(
|
||||
key="filter_cycle_1",
|
||||
name="Filter1",
|
||||
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="filter_cycle_2",
|
||||
name="Filter2",
|
||||
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(
|
||||
key="circulation_pump",
|
||||
name="Circ Pump",
|
||||
key="Circ Pump",
|
||||
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"),
|
||||
|
@ -87,7 +83,7 @@ class BalboaBinarySensorEntity(BalboaEntity, BinarySensorEntity):
|
|||
self, spa: SpaClient, description: BalboaBinarySensorEntityDescription
|
||||
) -> None:
|
||||
"""Initialize a Balboa binary sensor entity."""
|
||||
super().__init__(spa, description.name)
|
||||
super().__init__(spa, description.key)
|
||||
self.entity_description = description
|
||||
|
||||
@property
|
||||
|
|
|
@ -59,6 +59,7 @@ class BalboaClimateEntity(BalboaEntity, ClimateEntity):
|
|||
ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE
|
||||
)
|
||||
_attr_translation_key = DOMAIN
|
||||
_attr_name = None
|
||||
|
||||
def __init__(self, client: SpaClient) -> None:
|
||||
"""Initialize the climate entity."""
|
||||
|
|
|
@ -15,12 +15,11 @@ class BalboaEntity(Entity):
|
|||
_attr_should_poll = False
|
||||
_attr_has_entity_name = True
|
||||
|
||||
def __init__(self, client: SpaClient, name: str | None = None) -> None:
|
||||
def __init__(self, client: SpaClient, key: str) -> None:
|
||||
"""Initialize the control."""
|
||||
mac = client.mac_address
|
||||
model = client.model
|
||||
self._attr_unique_id = f'{model}-{name}-{mac.replace(":","")[-6:]}'
|
||||
self._attr_name = name
|
||||
self._attr_unique_id = f'{model}-{key}-{mac.replace(":","")[-6:]}'
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, mac)},
|
||||
name=model,
|
||||
|
|
|
@ -26,6 +26,17 @@
|
|||
}
|
||||
},
|
||||
"entity": {
|
||||
"binary_sensor": {
|
||||
"filter_1": {
|
||||
"name": "Filter cycle 1"
|
||||
},
|
||||
"filter_2": {
|
||||
"name": "Filter cycle 2"
|
||||
},
|
||||
"circ_pump": {
|
||||
"name": "Circulation pump"
|
||||
}
|
||||
},
|
||||
"climate": {
|
||||
"balboa": {
|
||||
"state_attributes": {
|
||||
|
|
|
@ -16,7 +16,7 @@ async def test_filters(
|
|||
) -> None:
|
||||
"""Test spa filters."""
|
||||
for num in (1, 2):
|
||||
sensor = f"{ENTITY_BINARY_SENSOR}filter{num}"
|
||||
sensor = f"{ENTITY_BINARY_SENSOR}filter_cycle_{num}"
|
||||
|
||||
state = hass.states.get(sensor)
|
||||
assert state.state == STATE_OFF
|
||||
|
@ -33,7 +33,7 @@ async def test_circ_pump(
|
|||
hass: HomeAssistant, client: MagicMock, integration: MockConfigEntry
|
||||
) -> None:
|
||||
"""Test spa circ pump."""
|
||||
sensor = f"{ENTITY_BINARY_SENSOR}circ_pump"
|
||||
sensor = f"{ENTITY_BINARY_SENSOR}circulation_pump"
|
||||
|
||||
state = hass.states.get(sensor)
|
||||
assert state.state == STATE_OFF
|
||||
|
|
|
@ -38,7 +38,7 @@ HVAC_SETTINGS = [
|
|||
HVACMode.AUTO,
|
||||
]
|
||||
|
||||
ENTITY_CLIMATE = "climate.fakespa_climate"
|
||||
ENTITY_CLIMATE = "climate.fakespa"
|
||||
|
||||
|
||||
async def test_spa_defaults(
|
||||
|
|
Loading…
Add table
Reference in a new issue