mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 09:47:52 +00:00
Add entity translations to Balboa (#104543)
This commit is contained in:
parent
e3599bc26f
commit
2e1c722303
@ -47,31 +47,27 @@ class BalboaBinarySensorEntityDescription(
|
|||||||
):
|
):
|
||||||
"""A class that describes Balboa binary sensor entities."""
|
"""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")
|
FILTER_CYCLE_ICONS = ("mdi:sync", "mdi:sync-off")
|
||||||
BINARY_SENSOR_DESCRIPTIONS = (
|
BINARY_SENSOR_DESCRIPTIONS = (
|
||||||
BalboaBinarySensorEntityDescription(
|
BalboaBinarySensorEntityDescription(
|
||||||
key="filter_cycle_1",
|
key="Filter1",
|
||||||
name="Filter1",
|
translation_key="filter_1",
|
||||||
device_class=BinarySensorDeviceClass.RUNNING,
|
device_class=BinarySensorDeviceClass.RUNNING,
|
||||||
is_on_fn=lambda spa: spa.filter_cycle_1_running,
|
is_on_fn=lambda spa: spa.filter_cycle_1_running,
|
||||||
on_off_icons=FILTER_CYCLE_ICONS,
|
on_off_icons=FILTER_CYCLE_ICONS,
|
||||||
),
|
),
|
||||||
BalboaBinarySensorEntityDescription(
|
BalboaBinarySensorEntityDescription(
|
||||||
key="filter_cycle_2",
|
key="Filter2",
|
||||||
name="Filter2",
|
translation_key="filter_2",
|
||||||
device_class=BinarySensorDeviceClass.RUNNING,
|
device_class=BinarySensorDeviceClass.RUNNING,
|
||||||
is_on_fn=lambda spa: spa.filter_cycle_2_running,
|
is_on_fn=lambda spa: spa.filter_cycle_2_running,
|
||||||
on_off_icons=FILTER_CYCLE_ICONS,
|
on_off_icons=FILTER_CYCLE_ICONS,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
CIRCULATION_PUMP_DESCRIPTION = BalboaBinarySensorEntityDescription(
|
CIRCULATION_PUMP_DESCRIPTION = BalboaBinarySensorEntityDescription(
|
||||||
key="circulation_pump",
|
key="Circ Pump",
|
||||||
name="Circ Pump",
|
translation_key="circ_pump",
|
||||||
device_class=BinarySensorDeviceClass.RUNNING,
|
device_class=BinarySensorDeviceClass.RUNNING,
|
||||||
is_on_fn=lambda spa: (pump := spa.circulation_pump) is not None and pump.state > 0,
|
is_on_fn=lambda spa: (pump := spa.circulation_pump) is not None and pump.state > 0,
|
||||||
on_off_icons=("mdi:pump", "mdi:pump-off"),
|
on_off_icons=("mdi:pump", "mdi:pump-off"),
|
||||||
@ -87,7 +83,7 @@ class BalboaBinarySensorEntity(BalboaEntity, BinarySensorEntity):
|
|||||||
self, spa: SpaClient, description: BalboaBinarySensorEntityDescription
|
self, spa: SpaClient, description: BalboaBinarySensorEntityDescription
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize a Balboa binary sensor entity."""
|
"""Initialize a Balboa binary sensor entity."""
|
||||||
super().__init__(spa, description.name)
|
super().__init__(spa, description.key)
|
||||||
self.entity_description = description
|
self.entity_description = description
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -59,6 +59,7 @@ class BalboaClimateEntity(BalboaEntity, ClimateEntity):
|
|||||||
ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE
|
ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE
|
||||||
)
|
)
|
||||||
_attr_translation_key = DOMAIN
|
_attr_translation_key = DOMAIN
|
||||||
|
_attr_name = None
|
||||||
|
|
||||||
def __init__(self, client: SpaClient) -> None:
|
def __init__(self, client: SpaClient) -> None:
|
||||||
"""Initialize the climate entity."""
|
"""Initialize the climate entity."""
|
||||||
|
@ -15,12 +15,11 @@ class BalboaEntity(Entity):
|
|||||||
_attr_should_poll = False
|
_attr_should_poll = False
|
||||||
_attr_has_entity_name = True
|
_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."""
|
"""Initialize the control."""
|
||||||
mac = client.mac_address
|
mac = client.mac_address
|
||||||
model = client.model
|
model = client.model
|
||||||
self._attr_unique_id = f'{model}-{name}-{mac.replace(":","")[-6:]}'
|
self._attr_unique_id = f'{model}-{key}-{mac.replace(":","")[-6:]}'
|
||||||
self._attr_name = name
|
|
||||||
self._attr_device_info = DeviceInfo(
|
self._attr_device_info = DeviceInfo(
|
||||||
identifiers={(DOMAIN, mac)},
|
identifiers={(DOMAIN, mac)},
|
||||||
name=model,
|
name=model,
|
||||||
|
@ -26,6 +26,17 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"entity": {
|
"entity": {
|
||||||
|
"binary_sensor": {
|
||||||
|
"filter_1": {
|
||||||
|
"name": "Filter cycle 1"
|
||||||
|
},
|
||||||
|
"filter_2": {
|
||||||
|
"name": "Filter cycle 2"
|
||||||
|
},
|
||||||
|
"circ_pump": {
|
||||||
|
"name": "Circulation pump"
|
||||||
|
}
|
||||||
|
},
|
||||||
"climate": {
|
"climate": {
|
||||||
"balboa": {
|
"balboa": {
|
||||||
"state_attributes": {
|
"state_attributes": {
|
||||||
|
@ -16,7 +16,7 @@ async def test_filters(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Test spa filters."""
|
"""Test spa filters."""
|
||||||
for num in (1, 2):
|
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)
|
state = hass.states.get(sensor)
|
||||||
assert state.state == STATE_OFF
|
assert state.state == STATE_OFF
|
||||||
@ -33,7 +33,7 @@ async def test_circ_pump(
|
|||||||
hass: HomeAssistant, client: MagicMock, integration: MockConfigEntry
|
hass: HomeAssistant, client: MagicMock, integration: MockConfigEntry
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test spa circ pump."""
|
"""Test spa circ pump."""
|
||||||
sensor = f"{ENTITY_BINARY_SENSOR}circ_pump"
|
sensor = f"{ENTITY_BINARY_SENSOR}circulation_pump"
|
||||||
|
|
||||||
state = hass.states.get(sensor)
|
state = hass.states.get(sensor)
|
||||||
assert state.state == STATE_OFF
|
assert state.state == STATE_OFF
|
||||||
|
@ -38,7 +38,7 @@ HVAC_SETTINGS = [
|
|||||||
HVACMode.AUTO,
|
HVACMode.AUTO,
|
||||||
]
|
]
|
||||||
|
|
||||||
ENTITY_CLIMATE = "climate.fakespa_climate"
|
ENTITY_CLIMATE = "climate.fakespa"
|
||||||
|
|
||||||
|
|
||||||
async def test_spa_defaults(
|
async def test_spa_defaults(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user