From a0a06f16a7c653e68aa5bea9bcf9f72dc639703a Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Tue, 22 Aug 2023 09:26:49 +0200 Subject: [PATCH] Add entity translations to Bosch SHC (#98750) --- .../components/bosch_shc/binary_sensor.py | 3 +- homeassistant/components/bosch_shc/cover.py | 1 + homeassistant/components/bosch_shc/entity.py | 2 +- homeassistant/components/bosch_shc/sensor.py | 22 +++++++------- .../components/bosch_shc/strings.json | 30 +++++++++++++++++++ homeassistant/components/bosch_shc/switch.py | 2 +- 6 files changed, 46 insertions(+), 14 deletions(-) diff --git a/homeassistant/components/bosch_shc/binary_sensor.py b/homeassistant/components/bosch_shc/binary_sensor.py index 348bfe80701..c9969fcf415 100644 --- a/homeassistant/components/bosch_shc/binary_sensor.py +++ b/homeassistant/components/bosch_shc/binary_sensor.py @@ -62,6 +62,8 @@ async def async_setup_entry( class ShutterContactSensor(SHCEntity, BinarySensorEntity): """Representation of an SHC shutter contact sensor.""" + _attr_name = None + def __init__(self, device: SHCDevice, parent_id: str, entry_id: str) -> None: """Initialize an SHC shutter contact sensor..""" super().__init__(device, parent_id, entry_id) @@ -89,7 +91,6 @@ class BatterySensor(SHCEntity, BinarySensorEntity): def __init__(self, device: SHCDevice, parent_id: str, entry_id: str) -> None: """Initialize an SHC battery reporting sensor.""" super().__init__(device, parent_id, entry_id) - self._attr_name = f"{device.name} Battery" self._attr_unique_id = f"{device.serial}_battery" @property diff --git a/homeassistant/components/bosch_shc/cover.py b/homeassistant/components/bosch_shc/cover.py index 3f1a9eccb93..8b2a2f65c12 100644 --- a/homeassistant/components/bosch_shc/cover.py +++ b/homeassistant/components/bosch_shc/cover.py @@ -42,6 +42,7 @@ async def async_setup_entry( class ShutterControlCover(SHCEntity, CoverEntity): """Representation of a SHC shutter control device.""" + _attr_name = None _attr_device_class = CoverDeviceClass.SHUTTER _attr_supported_features = ( CoverEntityFeature.OPEN diff --git a/homeassistant/components/bosch_shc/entity.py b/homeassistant/components/bosch_shc/entity.py index 5af77f8ee87..8c26d2e6d5a 100644 --- a/homeassistant/components/bosch_shc/entity.py +++ b/homeassistant/components/bosch_shc/entity.py @@ -24,6 +24,7 @@ class SHCBaseEntity(Entity): """Base representation of a SHC entity.""" _attr_should_poll = False + _attr_has_entity_name = True def __init__( self, device: SHCDevice | SHCIntrusionSystem, parent_id: str, entry_id: str @@ -31,7 +32,6 @@ class SHCBaseEntity(Entity): """Initialize the generic SHC device.""" self._device = device self._entry_id = entry_id - self._attr_name = device.name async def async_added_to_hass(self) -> None: """Subscribe to SHC events.""" diff --git a/homeassistant/components/bosch_shc/sensor.py b/homeassistant/components/bosch_shc/sensor.py index 73307d9ea0a..df216ed0ff2 100644 --- a/homeassistant/components/bosch_shc/sensor.py +++ b/homeassistant/components/bosch_shc/sensor.py @@ -170,7 +170,6 @@ class TemperatureSensor(SHCEntity, SensorEntity): def __init__(self, device: SHCDevice, parent_id: str, entry_id: str) -> None: """Initialize an SHC temperature reporting sensor.""" super().__init__(device, parent_id, entry_id) - self._attr_name = f"{device.name} Temperature" self._attr_unique_id = f"{device.serial}_temperature" @property @@ -188,7 +187,6 @@ class HumiditySensor(SHCEntity, SensorEntity): def __init__(self, device: SHCDevice, parent_id: str, entry_id: str) -> None: """Initialize an SHC humidity reporting sensor.""" super().__init__(device, parent_id, entry_id) - self._attr_name = f"{device.name} Humidity" self._attr_unique_id = f"{device.serial}_humidity" @property @@ -200,13 +198,13 @@ class HumiditySensor(SHCEntity, SensorEntity): class PuritySensor(SHCEntity, SensorEntity): """Representation of an SHC purity reporting sensor.""" + _attr_translation_key = "purity" _attr_icon = "mdi:molecule-co2" _attr_native_unit_of_measurement = CONCENTRATION_PARTS_PER_MILLION def __init__(self, device: SHCDevice, parent_id: str, entry_id: str) -> None: """Initialize an SHC purity reporting sensor.""" super().__init__(device, parent_id, entry_id) - self._attr_name = f"{device.name} Purity" self._attr_unique_id = f"{device.serial}_purity" @property @@ -218,10 +216,11 @@ class PuritySensor(SHCEntity, SensorEntity): class AirQualitySensor(SHCEntity, SensorEntity): """Representation of an SHC airquality reporting sensor.""" + _attr_translation_key = "air_quality" + def __init__(self, device: SHCDevice, parent_id: str, entry_id: str) -> None: """Initialize an SHC airquality reporting sensor.""" super().__init__(device, parent_id, entry_id) - self._attr_name = f"{device.name} Air Quality" self._attr_unique_id = f"{device.serial}_airquality" @property @@ -240,10 +239,11 @@ class AirQualitySensor(SHCEntity, SensorEntity): class TemperatureRatingSensor(SHCEntity, SensorEntity): """Representation of an SHC temperature rating sensor.""" + _attr_translation_key = "temperature_rating" + def __init__(self, device: SHCDevice, parent_id: str, entry_id: str) -> None: """Initialize an SHC temperature rating sensor.""" super().__init__(device, parent_id, entry_id) - self._attr_name = f"{device.name} Temperature Rating" self._attr_unique_id = f"{device.serial}_temperature_rating" @property @@ -255,12 +255,12 @@ class TemperatureRatingSensor(SHCEntity, SensorEntity): class CommunicationQualitySensor(SHCEntity, SensorEntity): """Representation of an SHC communication quality reporting sensor.""" + _attr_translation_key = "communication_quality" _attr_icon = "mdi:wifi" def __init__(self, device: SHCDevice, parent_id: str, entry_id: str) -> None: """Initialize an SHC communication quality reporting sensor.""" super().__init__(device, parent_id, entry_id) - self._attr_name = f"{device.name} Communication Quality" self._attr_unique_id = f"{device.serial}_communication_quality" @property @@ -272,10 +272,11 @@ class CommunicationQualitySensor(SHCEntity, SensorEntity): class HumidityRatingSensor(SHCEntity, SensorEntity): """Representation of an SHC humidity rating sensor.""" + _attr_translation_key = "humidity_rating" + def __init__(self, device: SHCDevice, parent_id: str, entry_id: str) -> None: """Initialize an SHC humidity rating sensor.""" super().__init__(device, parent_id, entry_id) - self._attr_name = f"{device.name} Humidity Rating" self._attr_unique_id = f"{device.serial}_humidity_rating" @property @@ -287,10 +288,11 @@ class HumidityRatingSensor(SHCEntity, SensorEntity): class PurityRatingSensor(SHCEntity, SensorEntity): """Representation of an SHC purity rating sensor.""" + _attr_translation_key = "purity_rating" + def __init__(self, device: SHCDevice, parent_id: str, entry_id: str) -> None: """Initialize an SHC purity rating sensor.""" super().__init__(device, parent_id, entry_id) - self._attr_name = f"{device.name} Purity Rating" self._attr_unique_id = f"{device.serial}_purity_rating" @property @@ -308,7 +310,6 @@ class PowerSensor(SHCEntity, SensorEntity): def __init__(self, device: SHCDevice, parent_id: str, entry_id: str) -> None: """Initialize an SHC power reporting sensor.""" super().__init__(device, parent_id, entry_id) - self._attr_name = f"{device.name} Power" self._attr_unique_id = f"{device.serial}_power" @property @@ -327,7 +328,6 @@ class EnergySensor(SHCEntity, SensorEntity): def __init__(self, device: SHCDevice, parent_id: str, entry_id: str) -> None: """Initialize an SHC energy reporting sensor.""" super().__init__(device, parent_id, entry_id) - self._attr_name = f"{self._device.name} Energy" self._attr_unique_id = f"{self._device.serial}_energy" @property @@ -340,13 +340,13 @@ class ValveTappetSensor(SHCEntity, SensorEntity): """Representation of an SHC valve tappet reporting sensor.""" _attr_icon = "mdi:gauge" + _attr_translation_key = "valvetappet" _attr_state_class = SensorStateClass.MEASUREMENT _attr_native_unit_of_measurement = PERCENTAGE def __init__(self, device: SHCDevice, parent_id: str, entry_id: str) -> None: """Initialize an SHC valve tappet reporting sensor.""" super().__init__(device, parent_id, entry_id) - self._attr_name = f"{device.name} Valvetappet" self._attr_unique_id = f"{device.serial}_valvetappet" @property diff --git a/homeassistant/components/bosch_shc/strings.json b/homeassistant/components/bosch_shc/strings.json index 2b5720f0849..67462b78bec 100644 --- a/homeassistant/components/bosch_shc/strings.json +++ b/homeassistant/components/bosch_shc/strings.json @@ -36,5 +36,35 @@ "reauth_successful": "[%key:common::config_flow::abort::reauth_successful%]" }, "flow_title": "Bosch SHC: {name}" + }, + "entity": { + "sensor": { + "purity_rating": { + "name": "Purity rating" + }, + "purity": { + "name": "Purity" + }, + "valvetappet": { + "name": "Valvetappet" + }, + "air_quality": { + "name": "Air quality" + }, + "temperature_rating": { + "name": "Temperature rating" + }, + "humidity_rating": { + "name": "Humidity rating" + }, + "communication_quality": { + "name": "Communication quality" + } + }, + "switch": { + "routing": { + "name": "Routing" + } + } } } diff --git a/homeassistant/components/bosch_shc/switch.py b/homeassistant/components/bosch_shc/switch.py index 3b3b6e2ffd4..25af0628780 100644 --- a/homeassistant/components/bosch_shc/switch.py +++ b/homeassistant/components/bosch_shc/switch.py @@ -200,12 +200,12 @@ class SHCRoutingSwitch(SHCEntity, SwitchEntity): """Representation of a SHC routing switch.""" _attr_icon = "mdi:wifi" + _attr_translation_key = "routing" _attr_entity_category = EntityCategory.CONFIG def __init__(self, device: SHCDevice, parent_id: str, entry_id: str) -> None: """Initialize an SHC communication quality reporting sensor.""" super().__init__(device, parent_id, entry_id) - self._attr_name = f"{device.name} Routing" self._attr_unique_id = f"{device.serial}_routing" @property