Add entity translations to FireServiceRota (#95337)

This commit is contained in:
Joost Lekkerkerker 2023-06-27 18:55:40 +02:00 committed by GitHub
parent 09bfb08067
commit e4eb7e4796
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 33 deletions

View File

@ -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."""

View File

@ -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."""

View File

@ -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"
}
}
}
}

View File

@ -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."""