Skip to content

Commit

Permalink
Add entity translations to Balboa (home-assistant#104543)
Browse files Browse the repository at this point in the history
  • Loading branch information
joostlek authored Nov 26, 2023
1 parent e3599bc commit 2e1c722
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 17 deletions.
18 changes: 7 additions & 11 deletions homeassistant/components/balboa/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -87,7 +83,7 @@ def __init__(
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
Expand Down
1 change: 1 addition & 0 deletions homeassistant/components/balboa/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
5 changes: 2 additions & 3 deletions homeassistant/components/balboa/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 11 additions & 0 deletions homeassistant/components/balboa/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
4 changes: 2 additions & 2 deletions tests/components/balboa/test_binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/components/balboa/test_climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
HVACMode.AUTO,
]

ENTITY_CLIMATE = "climate.fakespa_climate"
ENTITY_CLIMATE = "climate.fakespa"


async def test_spa_defaults(
Expand Down

0 comments on commit 2e1c722

Please sign in to comment.