From 1a8bc1930c5bb73286204cc2df47a70dbfa7457d Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Tue, 27 Jun 2023 18:44:26 +0200 Subject: [PATCH] Add entity translations to FiveM (#95370) --- .../components/fivem/binary_sensor.py | 2 +- homeassistant/components/fivem/entity.py | 3 ++- homeassistant/components/fivem/sensor.py | 6 +++--- homeassistant/components/fivem/strings.json | 18 ++++++++++++++++++ 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/fivem/binary_sensor.py b/homeassistant/components/fivem/binary_sensor.py index f6f8d0d11c1..153732d2ce5 100644 --- a/homeassistant/components/fivem/binary_sensor.py +++ b/homeassistant/components/fivem/binary_sensor.py @@ -24,7 +24,7 @@ class FiveMBinarySensorEntityDescription( BINARY_SENSORS: tuple[FiveMBinarySensorEntityDescription, ...] = ( FiveMBinarySensorEntityDescription( key=NAME_STATUS, - name=NAME_STATUS, + translation_key="status", device_class=BinarySensorDeviceClass.CONNECTIVITY, ), ) diff --git a/homeassistant/components/fivem/entity.py b/homeassistant/components/fivem/entity.py index a35c2b05ca3..53c35716276 100644 --- a/homeassistant/components/fivem/entity.py +++ b/homeassistant/components/fivem/entity.py @@ -30,6 +30,8 @@ class FiveMEntityDescription(EntityDescription): class FiveMEntity(CoordinatorEntity[FiveMDataUpdateCoordinator]): """Representation of a FiveM base entity.""" + _attr_has_entity_name = True + entity_description: FiveMEntityDescription def __init__( @@ -41,7 +43,6 @@ class FiveMEntity(CoordinatorEntity[FiveMDataUpdateCoordinator]): super().__init__(coordinator) 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_device_info = DeviceInfo( identifiers={(DOMAIN, self.coordinator.unique_id)}, diff --git a/homeassistant/components/fivem/sensor.py b/homeassistant/components/fivem/sensor.py index 12dd737ae60..1c4e4b77c45 100644 --- a/homeassistant/components/fivem/sensor.py +++ b/homeassistant/components/fivem/sensor.py @@ -32,20 +32,20 @@ class FiveMSensorEntityDescription(SensorEntityDescription, FiveMEntityDescripti SENSORS: tuple[FiveMSensorEntityDescription, ...] = ( FiveMSensorEntityDescription( key=NAME_PLAYERS_MAX, - name=NAME_PLAYERS_MAX, + translation_key="max_players", icon=ICON_PLAYERS_MAX, native_unit_of_measurement=UNIT_PLAYERS_MAX, ), FiveMSensorEntityDescription( key=NAME_PLAYERS_ONLINE, - name=NAME_PLAYERS_ONLINE, + translation_key="online_players", icon=ICON_PLAYERS_ONLINE, native_unit_of_measurement=UNIT_PLAYERS_ONLINE, extra_attrs=[ATTR_PLAYERS_LIST], ), FiveMSensorEntityDescription( key=NAME_RESOURCES, - name=NAME_RESOURCES, + translation_key="resources", icon=ICON_RESOURCES, native_unit_of_measurement=UNIT_RESOURCES, extra_attrs=[ATTR_RESOURCES_LIST], diff --git a/homeassistant/components/fivem/strings.json b/homeassistant/components/fivem/strings.json index 4378ef535bd..2ffb401f8c0 100644 --- a/homeassistant/components/fivem/strings.json +++ b/homeassistant/components/fivem/strings.json @@ -17,5 +17,23 @@ "abort": { "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" + } + } } }