From 2e1c722303ec54b64d2f247ac2218b76fdf4b67c Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Sun, 26 Nov 2023 13:07:21 +0100 Subject: [PATCH] Add entity translations to Balboa (#104543) --- .../components/balboa/binary_sensor.py | 18 +++++++----------- homeassistant/components/balboa/climate.py | 1 + homeassistant/components/balboa/entity.py | 5 ++--- homeassistant/components/balboa/strings.json | 11 +++++++++++ tests/components/balboa/test_binary_sensor.py | 4 ++-- tests/components/balboa/test_climate.py | 2 +- 6 files changed, 24 insertions(+), 17 deletions(-) diff --git a/homeassistant/components/balboa/binary_sensor.py b/homeassistant/components/balboa/binary_sensor.py index 9f363746a8f..7462d051643 100644 --- a/homeassistant/components/balboa/binary_sensor.py +++ b/homeassistant/components/balboa/binary_sensor.py @@ -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 diff --git a/homeassistant/components/balboa/climate.py b/homeassistant/components/balboa/climate.py index 0d0fa9bd179..d213a8fd2e8 100644 --- a/homeassistant/components/balboa/climate.py +++ b/homeassistant/components/balboa/climate.py @@ -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.""" diff --git a/homeassistant/components/balboa/entity.py b/homeassistant/components/balboa/entity.py index 3b4f7d08fff..e02579658da 100644 --- a/homeassistant/components/balboa/entity.py +++ b/homeassistant/components/balboa/entity.py @@ -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, diff --git a/homeassistant/components/balboa/strings.json b/homeassistant/components/balboa/strings.json index 214ccf8fbe1..238deb7d65d 100644 --- a/homeassistant/components/balboa/strings.json +++ b/homeassistant/components/balboa/strings.json @@ -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": { diff --git a/tests/components/balboa/test_binary_sensor.py b/tests/components/balboa/test_binary_sensor.py index e97887b154a..ee5f2bc353c 100644 --- a/tests/components/balboa/test_binary_sensor.py +++ b/tests/components/balboa/test_binary_sensor.py @@ -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 diff --git a/tests/components/balboa/test_climate.py b/tests/components/balboa/test_climate.py index 4967bcdfa38..90ef6c75e5f 100644 --- a/tests/components/balboa/test_climate.py +++ b/tests/components/balboa/test_climate.py @@ -38,7 +38,7 @@ HVAC_SETTINGS = [ HVACMode.AUTO, ] -ENTITY_CLIMATE = "climate.fakespa_climate" +ENTITY_CLIMATE = "climate.fakespa" async def test_spa_defaults(