From daa76bbab6e9b28dccc51edf329f28f0cda34b01 Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Mon, 24 Jul 2023 09:39:48 +0200 Subject: [PATCH] Migrate Yeelight to has entity naming (#96836) --- .../components/yeelight/binary_sensor.py | 7 ++--- homeassistant/components/yeelight/entity.py | 1 + homeassistant/components/yeelight/light.py | 29 +++++++++---------- .../components/yeelight/strings.json | 15 ++++++++++ 4 files changed, 32 insertions(+), 20 deletions(-) diff --git a/homeassistant/components/yeelight/binary_sensor.py b/homeassistant/components/yeelight/binary_sensor.py index f78b4e1401d..88779e03b6c 100644 --- a/homeassistant/components/yeelight/binary_sensor.py +++ b/homeassistant/components/yeelight/binary_sensor.py @@ -28,6 +28,8 @@ async def async_setup_entry( class YeelightNightlightModeSensor(YeelightEntity, BinarySensorEntity): """Representation of a Yeelight nightlight mode sensor.""" + _attr_translation_key = "nightlight" + async def async_added_to_hass(self) -> None: """Handle entity which will be added.""" self.async_on_remove( @@ -44,11 +46,6 @@ class YeelightNightlightModeSensor(YeelightEntity, BinarySensorEntity): """Return a unique ID.""" return f"{self._unique_id}-nightlight_sensor" - @property - def name(self): - """Return the name of the sensor.""" - return f"{self._device.name} nightlight" - @property def is_on(self): """Return true if nightlight mode is on.""" diff --git a/homeassistant/components/yeelight/entity.py b/homeassistant/components/yeelight/entity.py index 53211115dd6..9422ec9980d 100644 --- a/homeassistant/components/yeelight/entity.py +++ b/homeassistant/components/yeelight/entity.py @@ -12,6 +12,7 @@ class YeelightEntity(Entity): """Represents single Yeelight entity.""" _attr_should_poll = False + _attr_has_entity_name = True def __init__(self, device: YeelightDevice, entry: ConfigEntry) -> None: """Initialize the entity.""" diff --git a/homeassistant/components/yeelight/light.py b/homeassistant/components/yeelight/light.py index 9ac457b79e9..35739b0f596 100644 --- a/homeassistant/components/yeelight/light.py +++ b/homeassistant/components/yeelight/light.py @@ -472,11 +472,6 @@ class YeelightGenericLight(YeelightEntity, LightEntity): self._color_temp = kelvin_to_mired(int(temp_in_k)) return self._color_temp - @property - def name(self) -> str: - """Return the name of the device if any.""" - return self.device.name - @property def is_on(self) -> bool: """Return true if device is on.""" @@ -892,6 +887,7 @@ class YeelightColorLightSupport(YeelightGenericLight): class YeelightWhiteTempLightSupport(YeelightGenericLight): """Representation of a White temp Yeelight light.""" + _attr_name = None _attr_color_mode = ColorMode.COLOR_TEMP _attr_supported_color_modes = {ColorMode.COLOR_TEMP} @@ -943,6 +939,8 @@ class YeelightColorLightWithNightlightSwitch( It represents case when nightlight switch is set to light. """ + _attr_name = None + @property def is_on(self) -> bool: """Return true if device is on.""" @@ -954,6 +952,8 @@ class YeelightWhiteTempWithoutNightlightSwitch( ): """White temp light, when nightlight switch is not set to light.""" + _attr_name = None + class YeelightWithNightLight( YeelightNightLightSupport, YeelightWhiteTempLightSupport, YeelightGenericLight @@ -963,6 +963,8 @@ class YeelightWithNightLight( It represents case when nightlight switch is set to light. """ + _attr_name = None + @property def is_on(self) -> bool: """Return true if device is on.""" @@ -975,6 +977,7 @@ class YeelightNightLightMode(YeelightGenericLight): _attr_color_mode = ColorMode.BRIGHTNESS _attr_icon = "mdi:weather-night" _attr_supported_color_modes = {ColorMode.BRIGHTNESS} + _attr_translation_key = "nightlight" @property def unique_id(self) -> str: @@ -982,11 +985,6 @@ class YeelightNightLightMode(YeelightGenericLight): unique = super().unique_id return f"{unique}-nightlight" - @property - def name(self) -> str: - """Return the name of the device if any.""" - return f"{self.device.name} Nightlight" - @property def is_on(self) -> bool: """Return true if device is on.""" @@ -1030,6 +1028,8 @@ class YeelightWithAmbientWithoutNightlight(YeelightWhiteTempWithoutNightlightSwi And nightlight switch type is none. """ + _attr_name = None + @property def _power_property(self) -> str: return "main_power" @@ -1041,6 +1041,8 @@ class YeelightWithAmbientAndNightlight(YeelightWithNightLight): And nightlight switch type is set to light. """ + _attr_name = None + @property def _power_property(self) -> str: return "main_power" @@ -1049,6 +1051,8 @@ class YeelightWithAmbientAndNightlight(YeelightWithNightLight): class YeelightAmbientLight(YeelightColorLightWithoutNightlightSwitch): """Representation of a Yeelight ambient light.""" + _attr_translation_key = "ambilight" + PROPERTIES_MAPPING = {"color_mode": "bg_lmode"} def __init__(self, *args, **kwargs): @@ -1065,11 +1069,6 @@ class YeelightAmbientLight(YeelightColorLightWithoutNightlightSwitch): unique = super().unique_id return f"{unique}-ambilight" - @property - def name(self) -> str: - """Return the name of the device if any.""" - return f"{self.device.name} Ambilight" - @property def _brightness_property(self) -> str: return "bright" diff --git a/homeassistant/components/yeelight/strings.json b/homeassistant/components/yeelight/strings.json index 03a93bd9a5b..ab22f42dae3 100644 --- a/homeassistant/components/yeelight/strings.json +++ b/homeassistant/components/yeelight/strings.json @@ -38,6 +38,21 @@ } } }, + "entity": { + "binary_sensor": { + "nightlight": { + "name": "[%key:component::yeelight::entity::light::nightlight::name%]" + } + }, + "light": { + "nightlight": { + "name": "Nightlight" + }, + "ambilight": { + "name": "Ambilight" + } + } + }, "services": { "set_mode": { "name": "Set mode",