Add entity translations to FiveM (#95370)

pull/95394/head
Joost Lekkerkerker 2023-06-27 18:44:26 +02:00 committed by GitHub
parent 4b9bfe9a50
commit 1a8bc1930c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 5 deletions

View File

@ -24,7 +24,7 @@ class FiveMBinarySensorEntityDescription(
BINARY_SENSORS: tuple[FiveMBinarySensorEntityDescription, ...] = ( BINARY_SENSORS: tuple[FiveMBinarySensorEntityDescription, ...] = (
FiveMBinarySensorEntityDescription( FiveMBinarySensorEntityDescription(
key=NAME_STATUS, key=NAME_STATUS,
name=NAME_STATUS, translation_key="status",
device_class=BinarySensorDeviceClass.CONNECTIVITY, device_class=BinarySensorDeviceClass.CONNECTIVITY,
), ),
) )

View File

@ -30,6 +30,8 @@ class FiveMEntityDescription(EntityDescription):
class FiveMEntity(CoordinatorEntity[FiveMDataUpdateCoordinator]): class FiveMEntity(CoordinatorEntity[FiveMDataUpdateCoordinator]):
"""Representation of a FiveM base entity.""" """Representation of a FiveM base entity."""
_attr_has_entity_name = True
entity_description: FiveMEntityDescription entity_description: FiveMEntityDescription
def __init__( def __init__(
@ -41,7 +43,6 @@ class FiveMEntity(CoordinatorEntity[FiveMDataUpdateCoordinator]):
super().__init__(coordinator) super().__init__(coordinator)
self.entity_description = description self.entity_description = description
self._attr_name = f"{self.coordinator.host} {description.name}"
self._attr_unique_id = f"{self.coordinator.unique_id}-{description.key}".lower() self._attr_unique_id = f"{self.coordinator.unique_id}-{description.key}".lower()
self._attr_device_info = DeviceInfo( self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, self.coordinator.unique_id)}, identifiers={(DOMAIN, self.coordinator.unique_id)},

View File

@ -32,20 +32,20 @@ class FiveMSensorEntityDescription(SensorEntityDescription, FiveMEntityDescripti
SENSORS: tuple[FiveMSensorEntityDescription, ...] = ( SENSORS: tuple[FiveMSensorEntityDescription, ...] = (
FiveMSensorEntityDescription( FiveMSensorEntityDescription(
key=NAME_PLAYERS_MAX, key=NAME_PLAYERS_MAX,
name=NAME_PLAYERS_MAX, translation_key="max_players",
icon=ICON_PLAYERS_MAX, icon=ICON_PLAYERS_MAX,
native_unit_of_measurement=UNIT_PLAYERS_MAX, native_unit_of_measurement=UNIT_PLAYERS_MAX,
), ),
FiveMSensorEntityDescription( FiveMSensorEntityDescription(
key=NAME_PLAYERS_ONLINE, key=NAME_PLAYERS_ONLINE,
name=NAME_PLAYERS_ONLINE, translation_key="online_players",
icon=ICON_PLAYERS_ONLINE, icon=ICON_PLAYERS_ONLINE,
native_unit_of_measurement=UNIT_PLAYERS_ONLINE, native_unit_of_measurement=UNIT_PLAYERS_ONLINE,
extra_attrs=[ATTR_PLAYERS_LIST], extra_attrs=[ATTR_PLAYERS_LIST],
), ),
FiveMSensorEntityDescription( FiveMSensorEntityDescription(
key=NAME_RESOURCES, key=NAME_RESOURCES,
name=NAME_RESOURCES, translation_key="resources",
icon=ICON_RESOURCES, icon=ICON_RESOURCES,
native_unit_of_measurement=UNIT_RESOURCES, native_unit_of_measurement=UNIT_RESOURCES,
extra_attrs=[ATTR_RESOURCES_LIST], extra_attrs=[ATTR_RESOURCES_LIST],

View File

@ -17,5 +17,23 @@
"abort": { "abort": {
"already_configured": "[%key:common::config_flow::abort::already_configured_service%]" "already_configured": "[%key:common::config_flow::abort::already_configured_service%]"
} }
},
"entity": {
"binary_sensor": {
"status": {
"name": "Status"
}
},
"sensor": {
"max_players": {
"name": "Players max"
},
"online_players": {
"name": "Players online"
},
"resources": {
"name": "Resources"
}
}
} }
} }