mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Migrate abode light to color_mode (#69070)
This commit is contained in:
parent
0404c76c41
commit
1590c0a46c
@ -11,9 +11,10 @@ from homeassistant.components.light import (
|
||||
ATTR_BRIGHTNESS,
|
||||
ATTR_COLOR_TEMP,
|
||||
ATTR_HS_COLOR,
|
||||
SUPPORT_BRIGHTNESS,
|
||||
SUPPORT_COLOR,
|
||||
SUPPORT_COLOR_TEMP,
|
||||
COLOR_MODE_BRIGHTNESS,
|
||||
COLOR_MODE_COLOR_TEMP,
|
||||
COLOR_MODE_HS,
|
||||
COLOR_MODE_ONOFF,
|
||||
LightEntity,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
@ -101,11 +102,27 @@ class AbodeLight(AbodeDevice, LightEntity):
|
||||
_hs = self._device.color
|
||||
return _hs
|
||||
|
||||
@property
|
||||
def color_mode(self) -> str | None:
|
||||
"""Return the color mode of the light."""
|
||||
if self._device.is_dimmable and self._device.is_color_capable:
|
||||
if self.hs_color is not None:
|
||||
return COLOR_MODE_HS
|
||||
return COLOR_MODE_COLOR_TEMP
|
||||
if self._device.is_dimmable:
|
||||
return COLOR_MODE_BRIGHTNESS
|
||||
return COLOR_MODE_ONOFF
|
||||
|
||||
@property
|
||||
def supported_color_modes(self) -> set[str] | None:
|
||||
"""Flag supported color modes."""
|
||||
if self._device.is_dimmable and self._device.is_color_capable:
|
||||
return {COLOR_MODE_COLOR_TEMP, COLOR_MODE_HS}
|
||||
if self._device.is_dimmable:
|
||||
return {COLOR_MODE_BRIGHTNESS}
|
||||
return {COLOR_MODE_ONOFF}
|
||||
|
||||
@property
|
||||
def supported_features(self) -> int:
|
||||
"""Flag supported features."""
|
||||
if self._device.is_dimmable and self._device.is_color_capable:
|
||||
return SUPPORT_BRIGHTNESS | SUPPORT_COLOR | SUPPORT_COLOR_TEMP
|
||||
if self._device.is_dimmable:
|
||||
return SUPPORT_BRIGHTNESS
|
||||
return 0
|
||||
|
@ -4,8 +4,12 @@ from unittest.mock import patch
|
||||
from homeassistant.components.abode import ATTR_DEVICE_ID
|
||||
from homeassistant.components.light import (
|
||||
ATTR_BRIGHTNESS,
|
||||
ATTR_COLOR_MODE,
|
||||
ATTR_COLOR_TEMP,
|
||||
ATTR_RGB_COLOR,
|
||||
ATTR_SUPPORTED_COLOR_MODES,
|
||||
COLOR_MODE_COLOR_TEMP,
|
||||
COLOR_MODE_HS,
|
||||
DOMAIN as LIGHT_DOMAIN,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
@ -41,13 +45,18 @@ async def test_attributes(hass: HomeAssistant) -> None:
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes.get(ATTR_BRIGHTNESS) == 204
|
||||
assert state.attributes.get(ATTR_RGB_COLOR) == (0, 63, 255)
|
||||
assert state.attributes.get(ATTR_COLOR_TEMP) == 280
|
||||
assert state.attributes.get(ATTR_COLOR_TEMP) is None
|
||||
assert state.attributes.get(ATTR_DEVICE_ID) == "ZB:db5b1a"
|
||||
assert not state.attributes.get("battery_low")
|
||||
assert not state.attributes.get("no_response")
|
||||
assert state.attributes.get("device_type") == "RGB Dimmer"
|
||||
assert state.attributes.get(ATTR_FRIENDLY_NAME) == "Living Room Lamp"
|
||||
assert state.attributes.get(ATTR_SUPPORTED_FEATURES) == 19
|
||||
assert state.attributes.get(ATTR_SUPPORTED_FEATURES) == 0
|
||||
assert state.attributes.get(ATTR_COLOR_MODE) == COLOR_MODE_HS
|
||||
assert state.attributes.get(ATTR_SUPPORTED_COLOR_MODES) == [
|
||||
COLOR_MODE_COLOR_TEMP,
|
||||
COLOR_MODE_HS,
|
||||
]
|
||||
|
||||
|
||||
async def test_switch_off(hass: HomeAssistant) -> None:
|
||||
|
Loading…
x
Reference in New Issue
Block a user