From 9ef4b2e5f517152f88e78ad1312702e2014b5785 Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Sun, 9 Jul 2023 19:55:10 +0200 Subject: [PATCH] Migrate ring to entity name (#96080) Migrate ring to has entity name --- .../components/ring/binary_sensor.py | 4 +- homeassistant/components/ring/camera.py | 8 +--- homeassistant/components/ring/entity.py | 1 + homeassistant/components/ring/light.py | 6 +-- homeassistant/components/ring/sensor.py | 28 +++---------- homeassistant/components/ring/siren.py | 9 ++-- homeassistant/components/ring/strings.json | 42 +++++++++++++++++++ homeassistant/components/ring/switch.py | 7 +--- tests/components/ring/test_light.py | 4 +- tests/components/ring/test_switch.py | 4 +- 10 files changed, 63 insertions(+), 50 deletions(-) diff --git a/homeassistant/components/ring/binary_sensor.py b/homeassistant/components/ring/binary_sensor.py index d2c01bbd4f3..ab7207f0ac4 100644 --- a/homeassistant/components/ring/binary_sensor.py +++ b/homeassistant/components/ring/binary_sensor.py @@ -35,13 +35,12 @@ class RingBinarySensorEntityDescription( BINARY_SENSOR_TYPES: tuple[RingBinarySensorEntityDescription, ...] = ( RingBinarySensorEntityDescription( key="ding", - name="Ding", + translation_key="ding", category=["doorbots", "authorized_doorbots"], device_class=BinarySensorDeviceClass.OCCUPANCY, ), RingBinarySensorEntityDescription( key="motion", - name="Motion", category=["doorbots", "authorized_doorbots", "stickup_cams"], device_class=BinarySensorDeviceClass.MOTION, ), @@ -85,7 +84,6 @@ class RingBinarySensor(RingEntityMixin, BinarySensorEntity): super().__init__(config_entry_id, device) self.entity_description = description self._ring = ring - self._attr_name = f"{device.name} {description.name}" self._attr_unique_id = f"{device.id}-{description.key}" self._update_alert() diff --git a/homeassistant/components/ring/camera.py b/homeassistant/components/ring/camera.py index e99fabfab2f..0b3f1509b18 100644 --- a/homeassistant/components/ring/camera.py +++ b/homeassistant/components/ring/camera.py @@ -48,11 +48,12 @@ async def async_setup_entry( class RingCam(RingEntityMixin, Camera): """An implementation of a Ring Door Bell camera.""" + _attr_name = None + def __init__(self, config_entry_id, ffmpeg_manager, device): """Initialize a Ring Door Bell camera.""" super().__init__(config_entry_id, device) - self._name = self._device.name self._ffmpeg_manager = ffmpeg_manager self._last_event = None self._last_video_id = None @@ -90,11 +91,6 @@ class RingCam(RingEntityMixin, Camera): self._expires_at = dt_util.utcnow() self.async_write_ha_state() - @property - def name(self): - """Return the name of this camera.""" - return self._name - @property def unique_id(self): """Return a unique ID.""" diff --git a/homeassistant/components/ring/entity.py b/homeassistant/components/ring/entity.py index 16aa86511be..5fc438c2390 100644 --- a/homeassistant/components/ring/entity.py +++ b/homeassistant/components/ring/entity.py @@ -10,6 +10,7 @@ class RingEntityMixin(Entity): _attr_attribution = ATTRIBUTION _attr_should_poll = False + _attr_has_entity_name = True def __init__(self, config_entry_id, device): """Initialize a sensor for Ring device.""" diff --git a/homeassistant/components/ring/light.py b/homeassistant/components/ring/light.py index 143c333f600..2604e557b79 100644 --- a/homeassistant/components/ring/light.py +++ b/homeassistant/components/ring/light.py @@ -50,6 +50,7 @@ class RingLight(RingEntityMixin, LightEntity): _attr_color_mode = ColorMode.ONOFF _attr_supported_color_modes = {ColorMode.ONOFF} + _attr_translation_key = "light" def __init__(self, config_entry_id, device): """Initialize the light.""" @@ -67,11 +68,6 @@ class RingLight(RingEntityMixin, LightEntity): self._light_on = self._device.lights == ON_STATE self.async_write_ha_state() - @property - def name(self): - """Name of the light.""" - return f"{self._device.name} light" - @property def unique_id(self): """Return a unique ID.""" diff --git a/homeassistant/components/ring/sensor.py b/homeassistant/components/ring/sensor.py index 3d198ce7573..fbaeb8a4b5b 100644 --- a/homeassistant/components/ring/sensor.py +++ b/homeassistant/components/ring/sensor.py @@ -13,7 +13,6 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.const import PERCENTAGE, SIGNAL_STRENGTH_DECIBELS_MILLIWATT from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.entity_platform import AddEntitiesCallback -from homeassistant.helpers.icon import icon_for_battery_level from . import DOMAIN from .entity import RingEntityMixin @@ -53,8 +52,6 @@ class RingSensor(RingEntityMixin, SensorEntity): """Initialize a sensor for Ring device.""" super().__init__(config_entry_id, device) self.entity_description = description - self._extra = None - self._attr_name = f"{device.name} {description.name}" self._attr_unique_id = f"{device.id}-{description.key}" @property @@ -67,18 +64,6 @@ class RingSensor(RingEntityMixin, SensorEntity): if sensor_type == "battery": return self._device.battery_life - @property - def icon(self): - """Icon to use in the frontend, if any.""" - if ( - self.entity_description.key == "battery" - and self._device.battery_life is not None - ): - return icon_for_battery_level( - battery_level=self._device.battery_life, charging=False - ) - return self.entity_description.icon - class HealthDataRingSensor(RingSensor): """Ring sensor that relies on health data.""" @@ -204,7 +189,6 @@ class RingSensorEntityDescription(SensorEntityDescription, RingRequiredKeysMixin SENSOR_TYPES: tuple[RingSensorEntityDescription, ...] = ( RingSensorEntityDescription( key="battery", - name="Battery", category=["doorbots", "authorized_doorbots", "stickup_cams"], native_unit_of_measurement=PERCENTAGE, device_class=SensorDeviceClass.BATTERY, @@ -212,7 +196,7 @@ SENSOR_TYPES: tuple[RingSensorEntityDescription, ...] = ( ), RingSensorEntityDescription( key="last_activity", - name="Last Activity", + translation_key="last_activity", category=["doorbots", "authorized_doorbots", "stickup_cams"], icon="mdi:history", device_class=SensorDeviceClass.TIMESTAMP, @@ -220,7 +204,7 @@ SENSOR_TYPES: tuple[RingSensorEntityDescription, ...] = ( ), RingSensorEntityDescription( key="last_ding", - name="Last Ding", + translation_key="last_ding", category=["doorbots", "authorized_doorbots"], icon="mdi:history", kind="ding", @@ -229,7 +213,7 @@ SENSOR_TYPES: tuple[RingSensorEntityDescription, ...] = ( ), RingSensorEntityDescription( key="last_motion", - name="Last Motion", + translation_key="last_motion", category=["doorbots", "authorized_doorbots", "stickup_cams"], icon="mdi:history", kind="motion", @@ -238,21 +222,21 @@ SENSOR_TYPES: tuple[RingSensorEntityDescription, ...] = ( ), RingSensorEntityDescription( key="volume", - name="Volume", + translation_key="volume", category=["chimes", "doorbots", "authorized_doorbots", "stickup_cams"], icon="mdi:bell-ring", cls=RingSensor, ), RingSensorEntityDescription( key="wifi_signal_category", - name="WiFi Signal Category", + translation_key="wifi_signal_category", category=["chimes", "doorbots", "authorized_doorbots", "stickup_cams"], icon="mdi:wifi", cls=HealthDataRingSensor, ), RingSensorEntityDescription( key="wifi_signal_strength", - name="WiFi Signal Strength", + translation_key="wifi_signal_strength", category=["chimes", "doorbots", "authorized_doorbots", "stickup_cams"], native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS_MILLIWATT, icon="mdi:wifi", diff --git a/homeassistant/components/ring/siren.py b/homeassistant/components/ring/siren.py index 626444a9dcf..7f1b147471d 100644 --- a/homeassistant/components/ring/siren.py +++ b/homeassistant/components/ring/siren.py @@ -33,16 +33,15 @@ async def async_setup_entry( class RingChimeSiren(RingEntityMixin, SirenEntity): """Creates a siren to play the test chimes of a Chime device.""" + _attr_available_tones = CHIME_TEST_SOUND_KINDS + _attr_supported_features = SirenEntityFeature.TURN_ON | SirenEntityFeature.TONES + _attr_translation_key = "siren" + def __init__(self, config_entry: ConfigEntry, device) -> None: """Initialize a Ring Chime siren.""" super().__init__(config_entry.entry_id, device) # Entity class attributes - self._attr_name = f"{self._device.name} Siren" self._attr_unique_id = f"{self._device.id}-siren" - self._attr_available_tones = CHIME_TEST_SOUND_KINDS - self._attr_supported_features = ( - SirenEntityFeature.TURN_ON | SirenEntityFeature.TONES - ) def turn_on(self, **kwargs: Any) -> None: """Play the test sound on a Ring Chime device.""" diff --git a/homeassistant/components/ring/strings.json b/homeassistant/components/ring/strings.json index c5b448ad68b..43209a5a6a3 100644 --- a/homeassistant/components/ring/strings.json +++ b/homeassistant/components/ring/strings.json @@ -22,5 +22,47 @@ "abort": { "already_configured": "[%key:common::config_flow::abort::already_configured_device%]" } + }, + "entity": { + "binary_sensor": { + "ding": { + "name": "Ding" + } + }, + "light": { + "light": { + "name": "[%key:component::light::title%]" + } + }, + "siren": { + "siren": { + "name": "[%key:component::siren::title%]" + } + }, + "sensor": { + "last_activity": { + "name": "Last activity" + }, + "last_ding": { + "name": "Last ding" + }, + "last_motion": { + "name": "Last motion" + }, + "volume": { + "name": "Volume" + }, + "wifi_signal_category": { + "name": "Wi-Fi signal category" + }, + "wifi_signal_strength": { + "name": "Wi-Fi signal strength" + } + }, + "switch": { + "siren": { + "name": "[%key:component::siren::title%]" + } + } } } diff --git a/homeassistant/components/ring/switch.py b/homeassistant/components/ring/switch.py index 9a3c80114e9..43bd303577a 100644 --- a/homeassistant/components/ring/switch.py +++ b/homeassistant/components/ring/switch.py @@ -52,11 +52,6 @@ class BaseRingSwitch(RingEntityMixin, SwitchEntity): self._device_type = device_type self._unique_id = f"{self._device.id}-{self._device_type}" - @property - def name(self): - """Name of the device.""" - return f"{self._device.name} {self._device_type}" - @property def unique_id(self): """Return a unique ID.""" @@ -66,6 +61,8 @@ class BaseRingSwitch(RingEntityMixin, SwitchEntity): class SirenSwitch(BaseRingSwitch): """Creates a switch to turn the ring cameras siren on and off.""" + _attr_translation_key = "siren" + def __init__(self, config_entry_id, device): """Initialize the switch for a device with a siren.""" super().__init__(config_entry_id, device, "siren") diff --git a/tests/components/ring/test_light.py b/tests/components/ring/test_light.py index a2eb72c2711..7607f9fa5db 100644 --- a/tests/components/ring/test_light.py +++ b/tests/components/ring/test_light.py @@ -32,7 +32,7 @@ async def test_light_off_reports_correctly( state = hass.states.get("light.front_light") assert state.state == "off" - assert state.attributes.get("friendly_name") == "Front light" + assert state.attributes.get("friendly_name") == "Front Light" async def test_light_on_reports_correctly( @@ -43,7 +43,7 @@ async def test_light_on_reports_correctly( state = hass.states.get("light.internal_light") assert state.state == "on" - assert state.attributes.get("friendly_name") == "Internal light" + assert state.attributes.get("friendly_name") == "Internal Light" async def test_light_can_be_turned_on( diff --git a/tests/components/ring/test_switch.py b/tests/components/ring/test_switch.py index a33b9a0d732..468b4f0d0ec 100644 --- a/tests/components/ring/test_switch.py +++ b/tests/components/ring/test_switch.py @@ -32,7 +32,7 @@ async def test_siren_off_reports_correctly( state = hass.states.get("switch.front_siren") assert state.state == "off" - assert state.attributes.get("friendly_name") == "Front siren" + assert state.attributes.get("friendly_name") == "Front Siren" async def test_siren_on_reports_correctly( @@ -43,7 +43,7 @@ async def test_siren_on_reports_correctly( state = hass.states.get("switch.internal_siren") assert state.state == "on" - assert state.attributes.get("friendly_name") == "Internal siren" + assert state.attributes.get("friendly_name") == "Internal Siren" assert state.attributes.get("icon") == "mdi:alarm-bell"