From e4eb7e4796aecd599a7b1b9846567e48d5e93b4b Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Tue, 27 Jun 2023 18:55:40 +0200 Subject: [PATCH] Add entity translations to FireServiceRota (#95337) --- .../components/fireservicerota/binary_sensor.py | 15 ++++----------- .../components/fireservicerota/sensor.py | 14 +++----------- .../components/fireservicerota/strings.json | 17 +++++++++++++++++ .../components/fireservicerota/switch.py | 14 +++----------- 4 files changed, 27 insertions(+), 33 deletions(-) diff --git a/homeassistant/components/fireservicerota/binary_sensor.py b/homeassistant/components/fireservicerota/binary_sensor.py index 9e4d5b123f5..27f2c4a4526 100644 --- a/homeassistant/components/fireservicerota/binary_sensor.py +++ b/homeassistant/components/fireservicerota/binary_sensor.py @@ -35,6 +35,9 @@ async def async_setup_entry( class ResponseBinarySensor(CoordinatorEntity, BinarySensorEntity): """Representation of an FireServiceRota sensor.""" + _attr_has_entity_name = True + _attr_translation_key = "duty" + def __init__( self, coordinator: DataUpdateCoordinator, @@ -44,15 +47,10 @@ class ResponseBinarySensor(CoordinatorEntity, BinarySensorEntity): """Initialize.""" super().__init__(coordinator) self._client = client - self._unique_id = f"{entry.unique_id}_Duty" + self._attr_unique_id = f"{entry.unique_id}_Duty" self._state: bool | None = None - @property - def name(self) -> str: - """Return the name of the sensor.""" - return "Duty" - @property def icon(self) -> str: """Return the icon to use in the frontend.""" @@ -61,11 +59,6 @@ class ResponseBinarySensor(CoordinatorEntity, BinarySensorEntity): return "mdi:calendar-remove" - @property - def unique_id(self) -> str: - """Return the unique ID for this binary sensor.""" - return self._unique_id - @property def is_on(self) -> bool | None: """Return the state of the binary sensor.""" diff --git a/homeassistant/components/fireservicerota/sensor.py b/homeassistant/components/fireservicerota/sensor.py index 20f8589d2a2..797e39e99cd 100644 --- a/homeassistant/components/fireservicerota/sensor.py +++ b/homeassistant/components/fireservicerota/sensor.py @@ -28,20 +28,17 @@ class IncidentsSensor(RestoreEntity, SensorEntity): """Representation of FireServiceRota incidents sensor.""" _attr_should_poll = False + _attr_has_entity_name = True + _attr_translation_key = "incidents" def __init__(self, client): """Initialize.""" self._client = client self._entry_id = self._client.entry_id - self._unique_id = f"{self._client.unique_id}_Incidents" + self._attr_unique_id = f"{self._client.unique_id}_Incidents" self._state = None self._state_attributes = {} - @property - def name(self) -> str: - """Return the name of the sensor.""" - return "Incidents" - @property def icon(self) -> str: """Return the icon to use in the frontend.""" @@ -58,11 +55,6 @@ class IncidentsSensor(RestoreEntity, SensorEntity): """Return the state of the sensor.""" return self._state - @property - def unique_id(self) -> str: - """Return the unique ID of the sensor.""" - return self._unique_id - @property def extra_state_attributes(self) -> dict[str, Any]: """Return available attributes for sensor.""" diff --git a/homeassistant/components/fireservicerota/strings.json b/homeassistant/components/fireservicerota/strings.json index 7c60b438264..7b4bd583b63 100644 --- a/homeassistant/components/fireservicerota/strings.json +++ b/homeassistant/components/fireservicerota/strings.json @@ -25,5 +25,22 @@ "create_entry": { "default": "[%key:common::config_flow::create_entry::authenticated%]" } + }, + "entity": { + "binary_sensor": { + "duty": { + "name": "Duty" + } + }, + "sensor": { + "incidents": { + "name": "Incidents" + } + }, + "switch": { + "incident_response": { + "name": "Incident response" + } + } } } diff --git a/homeassistant/components/fireservicerota/switch.py b/homeassistant/components/fireservicerota/switch.py index 49c6d577b30..7409b2e53b4 100644 --- a/homeassistant/components/fireservicerota/switch.py +++ b/homeassistant/components/fireservicerota/switch.py @@ -28,23 +28,20 @@ class ResponseSwitch(SwitchEntity): """Representation of an FireServiceRota switch.""" _attr_should_poll = False + _attr_has_entity_name = True + _attr_translation_key = "incident_response" def __init__(self, coordinator, client, entry): """Initialize.""" self._coordinator = coordinator self._client = client - self._unique_id = f"{entry.unique_id}_Response" + self._attr_unique_id = f"{entry.unique_id}_Response" self._entry_id = entry.entry_id self._state = None self._state_attributes = {} self._state_icon = None - @property - def name(self) -> str: - """Return the name of the switch.""" - return "Incident Response" - @property def icon(self) -> str: """Return the icon to use in the frontend.""" @@ -60,11 +57,6 @@ class ResponseSwitch(SwitchEntity): """Get the assumed state of the switch.""" return self._state - @property - def unique_id(self) -> str: - """Return the unique ID for this switch.""" - return self._unique_id - @property def available(self) -> bool: """Return if switch is available."""