Migrate Yeelight to has entity naming (#96836)

This commit is contained in:
Joost Lekkerkerker 2023-07-24 09:39:48 +02:00 committed by GitHub
parent 0624345322
commit daa76bbab6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 20 deletions

View file

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

View file

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

View file

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

View file

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