mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Migrate bond light to color_mode (#69078)
This commit is contained in:
parent
aa969d5ae8
commit
66e9b263a8
@ -10,7 +10,8 @@ import voluptuous as vol
|
|||||||
|
|
||||||
from homeassistant.components.light import (
|
from homeassistant.components.light import (
|
||||||
ATTR_BRIGHTNESS,
|
ATTR_BRIGHTNESS,
|
||||||
SUPPORT_BRIGHTNESS,
|
COLOR_MODE_BRIGHTNESS,
|
||||||
|
COLOR_MODE_ONOFF,
|
||||||
LightEntity,
|
LightEntity,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
@ -126,7 +127,8 @@ async def async_setup_entry(
|
|||||||
class BondBaseLight(BondEntity, LightEntity):
|
class BondBaseLight(BondEntity, LightEntity):
|
||||||
"""Representation of a Bond light."""
|
"""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:
|
async def async_set_brightness_belief(self, brightness: int) -> None:
|
||||||
"""Set the belief state of the light."""
|
"""Set the belief state of the light."""
|
||||||
@ -170,7 +172,8 @@ class BondLight(BondBaseLight, BondEntity, LightEntity):
|
|||||||
"""Create HA entity representing Bond light."""
|
"""Create HA entity representing Bond light."""
|
||||||
super().__init__(hub, device, bpup_subs, sub_device)
|
super().__init__(hub, device, bpup_subs, sub_device)
|
||||||
if device.supports_set_brightness():
|
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:
|
def _apply_state(self, state: dict) -> None:
|
||||||
self._attr_is_on = state.get("light") == 1
|
self._attr_is_on = state.get("light") == 1
|
||||||
@ -267,7 +270,8 @@ class BondUpLight(BondBaseLight, BondEntity, LightEntity):
|
|||||||
class BondFireplace(BondEntity, LightEntity):
|
class BondFireplace(BondEntity, LightEntity):
|
||||||
"""Representation of a Bond-controlled fireplace."""
|
"""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:
|
def _apply_state(self, state: dict) -> None:
|
||||||
power = state.get("power")
|
power = state.get("power")
|
||||||
|
@ -18,8 +18,11 @@ from homeassistant.components.bond.light import (
|
|||||||
)
|
)
|
||||||
from homeassistant.components.light import (
|
from homeassistant.components.light import (
|
||||||
ATTR_BRIGHTNESS,
|
ATTR_BRIGHTNESS,
|
||||||
|
ATTR_COLOR_MODE,
|
||||||
|
ATTR_SUPPORTED_COLOR_MODES,
|
||||||
|
COLOR_MODE_BRIGHTNESS,
|
||||||
|
COLOR_MODE_ONOFF,
|
||||||
DOMAIN as LIGHT_DOMAIN,
|
DOMAIN as LIGHT_DOMAIN,
|
||||||
SUPPORT_BRIGHTNESS,
|
|
||||||
)
|
)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_ASSUMED_STATE,
|
ATTR_ASSUMED_STATE,
|
||||||
@ -723,7 +726,20 @@ async def test_brightness_support(hass: core.HomeAssistant):
|
|||||||
)
|
)
|
||||||
|
|
||||||
state = hass.states.get("light.name_1")
|
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):
|
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")
|
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):
|
async def test_turn_on_light_with_brightness(hass: core.HomeAssistant):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user