mirror of
https://github.com/home-assistant/core.git
synced 2025-07-10 06:47:09 +00:00
Migrate Yeelight to has entity naming (#96836)
This commit is contained in:
parent
0624345322
commit
daa76bbab6
@ -28,6 +28,8 @@ async def async_setup_entry(
|
|||||||
class YeelightNightlightModeSensor(YeelightEntity, BinarySensorEntity):
|
class YeelightNightlightModeSensor(YeelightEntity, BinarySensorEntity):
|
||||||
"""Representation of a Yeelight nightlight mode sensor."""
|
"""Representation of a Yeelight nightlight mode sensor."""
|
||||||
|
|
||||||
|
_attr_translation_key = "nightlight"
|
||||||
|
|
||||||
async def async_added_to_hass(self) -> None:
|
async def async_added_to_hass(self) -> None:
|
||||||
"""Handle entity which will be added."""
|
"""Handle entity which will be added."""
|
||||||
self.async_on_remove(
|
self.async_on_remove(
|
||||||
@ -44,11 +46,6 @@ class YeelightNightlightModeSensor(YeelightEntity, BinarySensorEntity):
|
|||||||
"""Return a unique ID."""
|
"""Return a unique ID."""
|
||||||
return f"{self._unique_id}-nightlight_sensor"
|
return f"{self._unique_id}-nightlight_sensor"
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self):
|
|
||||||
"""Return the name of the sensor."""
|
|
||||||
return f"{self._device.name} nightlight"
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
"""Return true if nightlight mode is on."""
|
"""Return true if nightlight mode is on."""
|
||||||
|
@ -12,6 +12,7 @@ class YeelightEntity(Entity):
|
|||||||
"""Represents single Yeelight entity."""
|
"""Represents single Yeelight entity."""
|
||||||
|
|
||||||
_attr_should_poll = False
|
_attr_should_poll = False
|
||||||
|
_attr_has_entity_name = True
|
||||||
|
|
||||||
def __init__(self, device: YeelightDevice, entry: ConfigEntry) -> None:
|
def __init__(self, device: YeelightDevice, entry: ConfigEntry) -> None:
|
||||||
"""Initialize the entity."""
|
"""Initialize the entity."""
|
||||||
|
@ -472,11 +472,6 @@ class YeelightGenericLight(YeelightEntity, LightEntity):
|
|||||||
self._color_temp = kelvin_to_mired(int(temp_in_k))
|
self._color_temp = kelvin_to_mired(int(temp_in_k))
|
||||||
return self._color_temp
|
return self._color_temp
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self) -> str:
|
|
||||||
"""Return the name of the device if any."""
|
|
||||||
return self.device.name
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self) -> bool:
|
def is_on(self) -> bool:
|
||||||
"""Return true if device is on."""
|
"""Return true if device is on."""
|
||||||
@ -892,6 +887,7 @@ class YeelightColorLightSupport(YeelightGenericLight):
|
|||||||
class YeelightWhiteTempLightSupport(YeelightGenericLight):
|
class YeelightWhiteTempLightSupport(YeelightGenericLight):
|
||||||
"""Representation of a White temp Yeelight light."""
|
"""Representation of a White temp Yeelight light."""
|
||||||
|
|
||||||
|
_attr_name = None
|
||||||
_attr_color_mode = ColorMode.COLOR_TEMP
|
_attr_color_mode = ColorMode.COLOR_TEMP
|
||||||
_attr_supported_color_modes = {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.
|
It represents case when nightlight switch is set to light.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
_attr_name = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self) -> bool:
|
def is_on(self) -> bool:
|
||||||
"""Return true if device is on."""
|
"""Return true if device is on."""
|
||||||
@ -954,6 +952,8 @@ class YeelightWhiteTempWithoutNightlightSwitch(
|
|||||||
):
|
):
|
||||||
"""White temp light, when nightlight switch is not set to light."""
|
"""White temp light, when nightlight switch is not set to light."""
|
||||||
|
|
||||||
|
_attr_name = None
|
||||||
|
|
||||||
|
|
||||||
class YeelightWithNightLight(
|
class YeelightWithNightLight(
|
||||||
YeelightNightLightSupport, YeelightWhiteTempLightSupport, YeelightGenericLight
|
YeelightNightLightSupport, YeelightWhiteTempLightSupport, YeelightGenericLight
|
||||||
@ -963,6 +963,8 @@ class YeelightWithNightLight(
|
|||||||
It represents case when nightlight switch is set to light.
|
It represents case when nightlight switch is set to light.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
_attr_name = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self) -> bool:
|
def is_on(self) -> bool:
|
||||||
"""Return true if device is on."""
|
"""Return true if device is on."""
|
||||||
@ -975,6 +977,7 @@ class YeelightNightLightMode(YeelightGenericLight):
|
|||||||
_attr_color_mode = ColorMode.BRIGHTNESS
|
_attr_color_mode = ColorMode.BRIGHTNESS
|
||||||
_attr_icon = "mdi:weather-night"
|
_attr_icon = "mdi:weather-night"
|
||||||
_attr_supported_color_modes = {ColorMode.BRIGHTNESS}
|
_attr_supported_color_modes = {ColorMode.BRIGHTNESS}
|
||||||
|
_attr_translation_key = "nightlight"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unique_id(self) -> str:
|
def unique_id(self) -> str:
|
||||||
@ -982,11 +985,6 @@ class YeelightNightLightMode(YeelightGenericLight):
|
|||||||
unique = super().unique_id
|
unique = super().unique_id
|
||||||
return f"{unique}-nightlight"
|
return f"{unique}-nightlight"
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self) -> str:
|
|
||||||
"""Return the name of the device if any."""
|
|
||||||
return f"{self.device.name} Nightlight"
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self) -> bool:
|
def is_on(self) -> bool:
|
||||||
"""Return true if device is on."""
|
"""Return true if device is on."""
|
||||||
@ -1030,6 +1028,8 @@ class YeelightWithAmbientWithoutNightlight(YeelightWhiteTempWithoutNightlightSwi
|
|||||||
And nightlight switch type is none.
|
And nightlight switch type is none.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
_attr_name = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _power_property(self) -> str:
|
def _power_property(self) -> str:
|
||||||
return "main_power"
|
return "main_power"
|
||||||
@ -1041,6 +1041,8 @@ class YeelightWithAmbientAndNightlight(YeelightWithNightLight):
|
|||||||
And nightlight switch type is set to light.
|
And nightlight switch type is set to light.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
_attr_name = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _power_property(self) -> str:
|
def _power_property(self) -> str:
|
||||||
return "main_power"
|
return "main_power"
|
||||||
@ -1049,6 +1051,8 @@ class YeelightWithAmbientAndNightlight(YeelightWithNightLight):
|
|||||||
class YeelightAmbientLight(YeelightColorLightWithoutNightlightSwitch):
|
class YeelightAmbientLight(YeelightColorLightWithoutNightlightSwitch):
|
||||||
"""Representation of a Yeelight ambient light."""
|
"""Representation of a Yeelight ambient light."""
|
||||||
|
|
||||||
|
_attr_translation_key = "ambilight"
|
||||||
|
|
||||||
PROPERTIES_MAPPING = {"color_mode": "bg_lmode"}
|
PROPERTIES_MAPPING = {"color_mode": "bg_lmode"}
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
@ -1065,11 +1069,6 @@ class YeelightAmbientLight(YeelightColorLightWithoutNightlightSwitch):
|
|||||||
unique = super().unique_id
|
unique = super().unique_id
|
||||||
return f"{unique}-ambilight"
|
return f"{unique}-ambilight"
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self) -> str:
|
|
||||||
"""Return the name of the device if any."""
|
|
||||||
return f"{self.device.name} Ambilight"
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _brightness_property(self) -> str:
|
def _brightness_property(self) -> str:
|
||||||
return "bright"
|
return "bright"
|
||||||
|
@ -38,6 +38,21 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"entity": {
|
||||||
|
"binary_sensor": {
|
||||||
|
"nightlight": {
|
||||||
|
"name": "[%key:component::yeelight::entity::light::nightlight::name%]"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"light": {
|
||||||
|
"nightlight": {
|
||||||
|
"name": "Nightlight"
|
||||||
|
},
|
||||||
|
"ambilight": {
|
||||||
|
"name": "Ambilight"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"services": {
|
"services": {
|
||||||
"set_mode": {
|
"set_mode": {
|
||||||
"name": "Set mode",
|
"name": "Set mode",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user