From acdf309c47d323fe82cc883d6db8d3f20dc9bb1f Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Thu, 22 Jun 2023 16:01:51 +0200 Subject: [PATCH] Add entity translations for Aladdin Connect (#95051) --- .../components/aladdin_connect/cover.py | 10 +++---- .../components/aladdin_connect/sensor.py | 27 ++++++++----------- .../components/aladdin_connect/strings.json | 10 +++++++ .../components/aladdin_connect/test_sensor.py | 10 +++---- 4 files changed, 30 insertions(+), 27 deletions(-) diff --git a/homeassistant/components/aladdin_connect/cover.py b/homeassistant/components/aladdin_connect/cover.py index 32eb34333c9..25d601cf299 100644 --- a/homeassistant/components/aladdin_connect/cover.py +++ b/homeassistant/components/aladdin_connect/cover.py @@ -40,26 +40,24 @@ class AladdinDevice(CoverEntity): _attr_device_class = CoverDeviceClass.GARAGE _attr_supported_features = SUPPORTED_FEATURES + _attr_has_entity_name = True + _attr_name = None def __init__( self, acc: AladdinConnectClient, device: DoorDevice, entry: ConfigEntry ) -> None: """Initialize the Aladdin Connect cover.""" self._acc = acc - self._entry_id = entry.entry_id self._device_id = device["device_id"] self._number = device["door_number"] - self._name = device["name"] self._serial = device["serial"] - self._model = device["model"] self._attr_device_info = DeviceInfo( identifiers={(DOMAIN, f"{self._device_id}-{self._number}")}, - name=self._name, + name=device["name"], manufacturer="Overhead Door", - model=self._model, + model=device["model"], ) - self._attr_has_entity_name = True self._attr_unique_id = f"{self._device_id}-{self._number}" async def async_added_to_hass(self) -> None: diff --git a/homeassistant/components/aladdin_connect/sensor.py b/homeassistant/components/aladdin_connect/sensor.py index 51ae5154302..395bbbb04a8 100644 --- a/homeassistant/components/aladdin_connect/sensor.py +++ b/homeassistant/components/aladdin_connect/sensor.py @@ -40,7 +40,6 @@ class AccSensorEntityDescription( SENSORS: tuple[AccSensorEntityDescription, ...] = ( AccSensorEntityDescription( key="battery_level", - name="Battery level", device_class=SensorDeviceClass.BATTERY, entity_registry_enabled_default=False, native_unit_of_measurement=PERCENTAGE, @@ -49,7 +48,7 @@ SENSORS: tuple[AccSensorEntityDescription, ...] = ( ), AccSensorEntityDescription( key="rssi", - name="Wi-Fi RSSI", + translation_key="wifi_strength", device_class=SensorDeviceClass.SIGNAL_STRENGTH, entity_registry_enabled_default=False, native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS, @@ -58,7 +57,7 @@ SENSORS: tuple[AccSensorEntityDescription, ...] = ( ), AccSensorEntityDescription( key="ble_strength", - name="BLE Strength", + translation_key="ble_strength", device_class=SensorDeviceClass.SIGNAL_STRENGTH, entity_registry_enabled_default=False, native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS, @@ -89,8 +88,8 @@ async def async_setup_entry( class AladdinConnectSensor(SensorEntity): """A sensor implementation for Aladdin Connect devices.""" - _device: AladdinConnectSensor entity_description: AccSensorEntityDescription + _attr_has_entity_name = True def __init__( self, @@ -101,24 +100,20 @@ class AladdinConnectSensor(SensorEntity): """Initialize a sensor for an Aladdin Connect device.""" self._device_id = device["device_id"] self._number = device["door_number"] - self._name = device["name"] - self._model = device["model"] self._acc = acc self.entity_description = description self._attr_unique_id = f"{self._device_id}-{self._number}-{description.key}" - self._attr_has_entity_name = True - if self._model == "01" and description.key in ("battery_level", "ble_strength"): - self._attr_entity_registry_enabled_default = True - - @property - def device_info(self) -> DeviceInfo | None: - """Device information for Aladdin Connect sensors.""" - return DeviceInfo( + self._attr_device_info = DeviceInfo( identifiers={(DOMAIN, f"{self._device_id}-{self._number}")}, - name=self._name, + name=device["name"], manufacturer="Overhead Door", - model=self._model, + model=device["model"], ) + if device["model"] == "01" and description.key in ( + "battery_level", + "ble_strength", + ): + self._attr_entity_registry_enabled_default = True @property def native_value(self) -> float | None: diff --git a/homeassistant/components/aladdin_connect/strings.json b/homeassistant/components/aladdin_connect/strings.json index ff42ca14bc3..bfe932b039c 100644 --- a/homeassistant/components/aladdin_connect/strings.json +++ b/homeassistant/components/aladdin_connect/strings.json @@ -25,5 +25,15 @@ "already_configured": "[%key:common::config_flow::abort::already_configured_device%]", "reauth_successful": "[%key:common::config_flow::abort::reauth_successful%]" } + }, + "entity": { + "sensor": { + "wifi_strength": { + "name": "Wi-Fi RSSI" + }, + "ble_strength": { + "name": "BLE Strength" + } + } } } diff --git a/tests/components/aladdin_connect/test_sensor.py b/tests/components/aladdin_connect/test_sensor.py index c01d6c5c781..dca8ecaa513 100644 --- a/tests/components/aladdin_connect/test_sensor.py +++ b/tests/components/aladdin_connect/test_sensor.py @@ -47,7 +47,7 @@ async def test_sensors( await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() - entry = entity_registry.async_get("sensor.home_battery_level") + entry = entity_registry.async_get("sensor.home_battery") assert entry assert entry.disabled assert entry.disabled_by is er.RegistryEntryDisabler.INTEGRATION @@ -57,7 +57,7 @@ async def test_sensors( await hass.async_block_till_done() assert update_entry != entry assert update_entry.disabled is False - state = hass.states.get("sensor.home_battery_level") + state = hass.states.get("sensor.home_battery") assert state is None async_fire_time_changed( @@ -65,7 +65,7 @@ async def test_sensors( utcnow() + SCAN_INTERVAL, ) await hass.async_block_till_done() - state = hass.states.get("sensor.home_battery_level") + state = hass.states.get("sensor.home_battery") assert state entry = entity_registry.async_get("sensor.home_wi_fi_rssi") @@ -121,11 +121,11 @@ async def test_sensors_model_01( await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() - entry = entity_registry.async_get("sensor.home_battery_level") + entry = entity_registry.async_get("sensor.home_battery") assert entry assert entry.disabled is False assert entry.disabled_by is None - state = hass.states.get("sensor.home_battery_level") + state = hass.states.get("sensor.home_battery") assert state entry = entity_registry.async_get("sensor.home_wi_fi_rssi")