Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 20 additions & 26 deletions homeassistant/components/xiaomi_miio/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
ATTR_BRIGHTNESS,
ATTR_COLOR_TEMP,
ATTR_HS_COLOR,
SUPPORT_BRIGHTNESS,
SUPPORT_COLOR,
SUPPORT_COLOR_TEMP,
ColorMode,
LightEntity,
)
from homeassistant.config_entries import ConfigEntry
Expand Down Expand Up @@ -232,6 +230,9 @@ async def async_service_handler(service: ServiceCall) -> None:
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)
Expand Down Expand Up @@ -261,11 +262,6 @@ def brightness(self):
"""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:
Expand Down Expand Up @@ -397,6 +393,9 @@ def delayed_turn_off_timestamp(
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)
Expand All @@ -418,11 +417,6 @@ def max_mireds(self):
"""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:
Expand Down Expand Up @@ -758,6 +752,8 @@ async def async_update(self):
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)
Expand Down Expand Up @@ -790,9 +786,11 @@ def hs_color(self) -> tuple:
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:
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be the same behavior as without the PR.
I don't think it's really correct though; the light will be stuck in hs mode once a color is set.

Does the miio library offer any way to get the color mode for a PhilipsMoonlight?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The library does not provide that at the moment and I'm not sure if it can be derived from the data returned by the device. Maybe @syssi knows if that's even possible?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rytilahti @syssi If the library offers no way to get the color mode I suggest to merge this PR, it should not result in any changed behavior

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine as an (intermediate) solution.

return ColorMode.HS
return ColorMode.COLOR_TEMP

async def async_turn_on(self, **kwargs):
"""Turn the light on."""
Expand Down Expand Up @@ -933,6 +931,9 @@ async def async_set_delayed_turn_off(self, time_period: timedelta):
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
Expand Down Expand Up @@ -982,11 +983,6 @@ def hs_color(self):
"""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:
Expand Down Expand Up @@ -1034,6 +1030,9 @@ async def async_update(self):
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."""
Expand All @@ -1059,11 +1058,6 @@ def max_mireds(self):
"""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)
Expand Down