mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 13:47:35 +00:00
Migrate lcn light to color_mode (#69419)
This commit is contained in:
parent
4f494a876e
commit
e8852e0f30
@ -8,8 +8,9 @@ import pypck
|
|||||||
from homeassistant.components.light import (
|
from homeassistant.components.light import (
|
||||||
ATTR_BRIGHTNESS,
|
ATTR_BRIGHTNESS,
|
||||||
ATTR_TRANSITION,
|
ATTR_TRANSITION,
|
||||||
|
COLOR_MODE_BRIGHTNESS,
|
||||||
|
COLOR_MODE_ONOFF,
|
||||||
DOMAIN as DOMAIN_LIGHT,
|
DOMAIN as DOMAIN_LIGHT,
|
||||||
SUPPORT_BRIGHTNESS,
|
|
||||||
SUPPORT_TRANSITION,
|
SUPPORT_TRANSITION,
|
||||||
LightEntity,
|
LightEntity,
|
||||||
)
|
)
|
||||||
@ -64,6 +65,8 @@ async def async_setup_entry(
|
|||||||
class LcnOutputLight(LcnEntity, LightEntity):
|
class LcnOutputLight(LcnEntity, LightEntity):
|
||||||
"""Representation of a LCN light for output ports."""
|
"""Representation of a LCN light for output ports."""
|
||||||
|
|
||||||
|
_attr_supported_features = SUPPORT_TRANSITION
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, config: ConfigType, entry_id: str, device_connection: DeviceConnectionType
|
self, config: ConfigType, entry_id: str, device_connection: DeviceConnectionType
|
||||||
) -> None:
|
) -> None:
|
||||||
@ -81,6 +84,12 @@ class LcnOutputLight(LcnEntity, LightEntity):
|
|||||||
self._is_on = False
|
self._is_on = False
|
||||||
self._is_dimming_to_zero = False
|
self._is_dimming_to_zero = False
|
||||||
|
|
||||||
|
if self.dimmable:
|
||||||
|
self._attr_color_mode = COLOR_MODE_BRIGHTNESS
|
||||||
|
else:
|
||||||
|
self._attr_color_mode = COLOR_MODE_ONOFF
|
||||||
|
self._attr_supported_color_modes = {self._attr_color_mode}
|
||||||
|
|
||||||
async def async_added_to_hass(self) -> None:
|
async def async_added_to_hass(self) -> None:
|
||||||
"""Run when entity about to be added to hass."""
|
"""Run when entity about to be added to hass."""
|
||||||
await super().async_added_to_hass()
|
await super().async_added_to_hass()
|
||||||
@ -93,13 +102,6 @@ class LcnOutputLight(LcnEntity, LightEntity):
|
|||||||
if not self.device_connection.is_group:
|
if not self.device_connection.is_group:
|
||||||
await self.device_connection.cancel_status_request_handler(self.output)
|
await self.device_connection.cancel_status_request_handler(self.output)
|
||||||
|
|
||||||
@property
|
|
||||||
def supported_features(self) -> int:
|
|
||||||
"""Flag supported features."""
|
|
||||||
if self.dimmable:
|
|
||||||
return SUPPORT_TRANSITION | SUPPORT_BRIGHTNESS
|
|
||||||
return SUPPORT_TRANSITION
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def brightness(self) -> int | None:
|
def brightness(self) -> int | None:
|
||||||
"""Return the brightness of this light between 0..255."""
|
"""Return the brightness of this light between 0..255."""
|
||||||
@ -167,6 +169,9 @@ class LcnOutputLight(LcnEntity, LightEntity):
|
|||||||
class LcnRelayLight(LcnEntity, LightEntity):
|
class LcnRelayLight(LcnEntity, LightEntity):
|
||||||
"""Representation of a LCN light for relay ports."""
|
"""Representation of a LCN light for relay ports."""
|
||||||
|
|
||||||
|
_attr_color_mode = COLOR_MODE_ONOFF
|
||||||
|
_attr_supported_color_modes = {COLOR_MODE_ONOFF}
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, config: ConfigType, entry_id: str, device_connection: DeviceConnectionType
|
self, config: ConfigType, entry_id: str, device_connection: DeviceConnectionType
|
||||||
) -> None:
|
) -> None:
|
||||||
|
@ -8,9 +8,11 @@ from pypck.lcn_defs import RelayStateModifier
|
|||||||
from homeassistant.components.lcn.helpers import get_device_connection
|
from homeassistant.components.lcn.helpers import get_device_connection
|
||||||
from homeassistant.components.light import (
|
from homeassistant.components.light import (
|
||||||
ATTR_BRIGHTNESS,
|
ATTR_BRIGHTNESS,
|
||||||
|
ATTR_SUPPORTED_COLOR_MODES,
|
||||||
ATTR_TRANSITION,
|
ATTR_TRANSITION,
|
||||||
|
COLOR_MODE_BRIGHTNESS,
|
||||||
|
COLOR_MODE_ONOFF,
|
||||||
DOMAIN as DOMAIN_LIGHT,
|
DOMAIN as DOMAIN_LIGHT,
|
||||||
SUPPORT_BRIGHTNESS,
|
|
||||||
SUPPORT_TRANSITION,
|
SUPPORT_TRANSITION,
|
||||||
)
|
)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
@ -42,14 +44,13 @@ async def test_entity_state(hass, lcn_connection):
|
|||||||
"""Test state of entity."""
|
"""Test state of entity."""
|
||||||
state = hass.states.get("light.light_output1")
|
state = hass.states.get("light.light_output1")
|
||||||
assert state
|
assert state
|
||||||
assert (
|
assert state.attributes[ATTR_SUPPORTED_FEATURES] == SUPPORT_TRANSITION
|
||||||
state.attributes[ATTR_SUPPORTED_FEATURES]
|
assert state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [COLOR_MODE_BRIGHTNESS]
|
||||||
== SUPPORT_BRIGHTNESS | SUPPORT_TRANSITION
|
|
||||||
)
|
|
||||||
|
|
||||||
state = hass.states.get("light.light_output2")
|
state = hass.states.get("light.light_output2")
|
||||||
assert state
|
assert state
|
||||||
assert state.attributes[ATTR_SUPPORTED_FEATURES] == SUPPORT_TRANSITION
|
assert state.attributes[ATTR_SUPPORTED_FEATURES] == SUPPORT_TRANSITION
|
||||||
|
assert state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [COLOR_MODE_ONOFF]
|
||||||
|
|
||||||
|
|
||||||
async def test_entity_attributes(hass, entry, lcn_connection):
|
async def test_entity_attributes(hass, entry, lcn_connection):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user