Migrate bond light to color_mode (#69078)
This commit is contained in:
parent
aa969d5ae8
commit
66e9b263a8
2 changed files with 40 additions and 7 deletions
|
@ -10,7 +10,8 @@ import voluptuous as vol
|
|||
|
||||
from homeassistant.components.light import (
|
||||
ATTR_BRIGHTNESS,
|
||||
SUPPORT_BRIGHTNESS,
|
||||
COLOR_MODE_BRIGHTNESS,
|
||||
COLOR_MODE_ONOFF,
|
||||
LightEntity,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
|
@ -126,7 +127,8 @@ async def async_setup_entry(
|
|||
class BondBaseLight(BondEntity, LightEntity):
|
||||
"""Representation of a Bond light."""
|
||||
|
||||
_attr_supported_features = 0
|
||||
_attr_color_mode = COLOR_MODE_ONOFF
|
||||
_attr_supported_color_modes = {COLOR_MODE_ONOFF}
|
||||
|
||||
async def async_set_brightness_belief(self, brightness: int) -> None:
|
||||
"""Set the belief state of the light."""
|
||||
|
@ -170,7 +172,8 @@ class BondLight(BondBaseLight, BondEntity, LightEntity):
|
|||
"""Create HA entity representing Bond light."""
|
||||
super().__init__(hub, device, bpup_subs, sub_device)
|
||||
if device.supports_set_brightness():
|
||||
self._attr_supported_features = SUPPORT_BRIGHTNESS
|
||||
self._attr_color_mode = COLOR_MODE_BRIGHTNESS
|
||||
self._attr_supported_color_modes = {COLOR_MODE_BRIGHTNESS}
|
||||
|
||||
def _apply_state(self, state: dict) -> None:
|
||||
self._attr_is_on = state.get("light") == 1
|
||||
|
@ -267,7 +270,8 @@ class BondUpLight(BondBaseLight, BondEntity, LightEntity):
|
|||
class BondFireplace(BondEntity, LightEntity):
|
||||
"""Representation of a Bond-controlled fireplace."""
|
||||
|
||||
_attr_supported_features = SUPPORT_BRIGHTNESS
|
||||
_attr_color_mode = COLOR_MODE_BRIGHTNESS
|
||||
_attr_supported_color_modes = {COLOR_MODE_BRIGHTNESS}
|
||||
|
||||
def _apply_state(self, state: dict) -> None:
|
||||
power = state.get("power")
|
||||
|
|
|
@ -18,8 +18,11 @@ from homeassistant.components.bond.light import (
|
|||
)
|
||||
from homeassistant.components.light import (
|
||||
ATTR_BRIGHTNESS,
|
||||
ATTR_COLOR_MODE,
|
||||
ATTR_SUPPORTED_COLOR_MODES,
|
||||
COLOR_MODE_BRIGHTNESS,
|
||||
COLOR_MODE_ONOFF,
|
||||
DOMAIN as LIGHT_DOMAIN,
|
||||
SUPPORT_BRIGHTNESS,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
ATTR_ASSUMED_STATE,
|
||||
|
@ -723,7 +726,20 @@ async def test_brightness_support(hass: core.HomeAssistant):
|
|||
)
|
||||
|
||||
state = hass.states.get("light.name_1")
|
||||
assert state.attributes[ATTR_SUPPORTED_FEATURES] & SUPPORT_BRIGHTNESS
|
||||
assert state.state == "off"
|
||||
assert ATTR_COLOR_MODE not in state.attributes
|
||||
assert state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [COLOR_MODE_BRIGHTNESS]
|
||||
assert state.attributes[ATTR_SUPPORTED_FEATURES] == 0
|
||||
|
||||
with patch_bond_device_state(return_value={"light": 1, "brightness": 50}):
|
||||
async_fire_time_changed(hass, utcnow() + timedelta(seconds=30))
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("light.name_1")
|
||||
assert state.state == "on"
|
||||
assert state.attributes[ATTR_COLOR_MODE] == COLOR_MODE_BRIGHTNESS
|
||||
assert state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [COLOR_MODE_BRIGHTNESS]
|
||||
assert state.attributes[ATTR_SUPPORTED_FEATURES] == 0
|
||||
|
||||
|
||||
async def test_brightness_not_supported(hass: core.HomeAssistant):
|
||||
|
@ -736,7 +752,20 @@ async def test_brightness_not_supported(hass: core.HomeAssistant):
|
|||
)
|
||||
|
||||
state = hass.states.get("light.name_1")
|
||||
assert not state.attributes[ATTR_SUPPORTED_FEATURES] & SUPPORT_BRIGHTNESS
|
||||
assert state.state == "off"
|
||||
assert ATTR_COLOR_MODE not in state.attributes
|
||||
assert state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [COLOR_MODE_ONOFF]
|
||||
assert state.attributes[ATTR_SUPPORTED_FEATURES] == 0
|
||||
|
||||
with patch_bond_device_state(return_value={"light": 1}):
|
||||
async_fire_time_changed(hass, utcnow() + timedelta(seconds=30))
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("light.name_1")
|
||||
assert state.state == "on"
|
||||
assert state.attributes[ATTR_COLOR_MODE] == COLOR_MODE_ONOFF
|
||||
assert state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [COLOR_MODE_ONOFF]
|
||||
assert state.attributes[ATTR_SUPPORTED_FEATURES] == 0
|
||||
|
||||
|
||||
async def test_turn_on_light_with_brightness(hass: core.HomeAssistant):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue