Migrate ring to entity name (#96080)

Migrate ring to has entity name
This commit is contained in:
Joost Lekkerkerker 2023-07-09 19:55:10 +02:00 committed by GitHub
parent cfe57f7e0c
commit 9ef4b2e5f5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 63 additions and 50 deletions

View file

@ -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()

View file

@ -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."""

View file

@ -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."""

View file

@ -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."""

View file

@ -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",

View file

@ -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."""

View file

@ -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%]"
}
}
}
}

View file

@ -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")

View file

@ -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(

View file

@ -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"