Migrate xiaomi_miio light to color_mode (#70998)

pull/72576/head
Erik Montnemery 2022-05-27 08:36:32 +02:00 committed by GitHub
parent cbd0c8976b
commit cc42a95100
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 26 deletions

View File

@ -19,9 +19,7 @@ from homeassistant.components.light import (
ATTR_BRIGHTNESS,
ATTR_COLOR_TEMP,
ATTR_HS_COLOR,
SUPPORT_BRIGHTNESS,
SUPPORT_COLOR,
SUPPORT_COLOR_TEMP,
ColorMode,
LightEntity,
)
from homeassistant.config_entries import ConfigEntry
@ -234,6 +232,9 @@ async def async_setup_entry(
class XiaomiPhilipsAbstractLight(XiaomiMiioEntity, LightEntity):
"""Representation of a Abstract Xiaomi Philips Light."""
_attr_color_mode = ColorMode.BRIGHTNESS
_attr_supported_color_modes = {ColorMode.BRIGHTNESS}
def __init__(self, name, device, entry, unique_id):
"""Initialize the light device."""
super().__init__(name, device, entry, unique_id)
@ -263,11 +264,6 @@ class XiaomiPhilipsAbstractLight(XiaomiMiioEntity, LightEntity):
"""Return the brightness of this light between 0..255."""
return self._brightness
@property
def supported_features(self):
"""Return the supported features."""
return SUPPORT_BRIGHTNESS
async def _try_command(self, mask_error, func, *args, **kwargs):
"""Call a light command handling error messages."""
try:
@ -399,6 +395,9 @@ class XiaomiPhilipsGenericLight(XiaomiPhilipsAbstractLight):
class XiaomiPhilipsBulb(XiaomiPhilipsGenericLight):
"""Representation of a Xiaomi Philips Bulb."""
_attr_color_mode = ColorMode.COLOR_TEMP
_attr_supported_color_modes = {ColorMode.COLOR_TEMP}
def __init__(self, name, device, entry, unique_id):
"""Initialize the light device."""
super().__init__(name, device, entry, unique_id)
@ -420,11 +419,6 @@ class XiaomiPhilipsBulb(XiaomiPhilipsGenericLight):
"""Return the warmest color_temp that this light supports."""
return 333
@property
def supported_features(self):
"""Return the supported features."""
return SUPPORT_BRIGHTNESS | SUPPORT_COLOR_TEMP
async def async_turn_on(self, **kwargs):
"""Turn the light on."""
if ATTR_COLOR_TEMP in kwargs:
@ -760,6 +754,8 @@ class XiaomiPhilipsEyecareLampAmbientLight(XiaomiPhilipsAbstractLight):
class XiaomiPhilipsMoonlightLamp(XiaomiPhilipsBulb):
"""Representation of a Xiaomi Philips Zhirui Bedside Lamp."""
_attr_supported_color_modes = {ColorMode.COLOR_TEMP, ColorMode.HS}
def __init__(self, name, device, entry, unique_id):
"""Initialize the light device."""
super().__init__(name, device, entry, unique_id)
@ -792,9 +788,11 @@ class XiaomiPhilipsMoonlightLamp(XiaomiPhilipsBulb):
return self._hs_color
@property
def supported_features(self):
"""Return the supported features."""
return SUPPORT_BRIGHTNESS | SUPPORT_COLOR | SUPPORT_COLOR_TEMP
def color_mode(self):
"""Return the color mode of the light."""
if self.hs_color:
return ColorMode.HS
return ColorMode.COLOR_TEMP
async def async_turn_on(self, **kwargs):
"""Turn the light on."""
@ -935,6 +933,9 @@ class XiaomiPhilipsMoonlightLamp(XiaomiPhilipsBulb):
class XiaomiGatewayLight(LightEntity):
"""Representation of a gateway device's light."""
_attr_color_mode = ColorMode.HS
_attr_supported_color_modes = {ColorMode.HS}
def __init__(self, gateway_device, gateway_name, gateway_device_id):
"""Initialize the XiaomiGatewayLight."""
self._gateway = gateway_device
@ -984,11 +985,6 @@ class XiaomiGatewayLight(LightEntity):
"""Return the hs color value."""
return self._hs
@property
def supported_features(self):
"""Return the supported features."""
return SUPPORT_BRIGHTNESS | SUPPORT_COLOR
def turn_on(self, **kwargs):
"""Turn the light on."""
if ATTR_HS_COLOR in kwargs:
@ -1036,6 +1032,9 @@ class XiaomiGatewayLight(LightEntity):
class XiaomiGatewayBulb(XiaomiGatewayDevice, LightEntity):
"""Representation of Xiaomi Gateway Bulb."""
_attr_color_mode = ColorMode.COLOR_TEMP
_attr_supported_color_modes = {ColorMode.COLOR_TEMP}
@property
def brightness(self):
"""Return the brightness of the light."""
@ -1061,11 +1060,6 @@ class XiaomiGatewayBulb(XiaomiGatewayDevice, LightEntity):
"""Return max cct."""
return self._sub_device.status["cct_max"]
@property
def supported_features(self):
"""Return the supported features."""
return SUPPORT_BRIGHTNESS | SUPPORT_COLOR_TEMP
async def async_turn_on(self, **kwargs):
"""Instruct the light to turn on."""
await self.hass.async_add_executor_job(self._sub_device.on)