Migrate lcn light to color_mode (#69419)

This commit is contained in:
Erik Montnemery 2022-04-07 14:49:12 +02:00 committed by GitHub
parent 4f494a876e
commit e8852e0f30
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 13 deletions

View file

@ -8,8 +8,9 @@ import pypck
from homeassistant.components.light import (
ATTR_BRIGHTNESS,
ATTR_TRANSITION,
COLOR_MODE_BRIGHTNESS,
COLOR_MODE_ONOFF,
DOMAIN as DOMAIN_LIGHT,
SUPPORT_BRIGHTNESS,
SUPPORT_TRANSITION,
LightEntity,
)
@ -64,6 +65,8 @@ async def async_setup_entry(
class LcnOutputLight(LcnEntity, LightEntity):
"""Representation of a LCN light for output ports."""
_attr_supported_features = SUPPORT_TRANSITION
def __init__(
self, config: ConfigType, entry_id: str, device_connection: DeviceConnectionType
) -> None:
@ -81,6 +84,12 @@ class LcnOutputLight(LcnEntity, LightEntity):
self._is_on = 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:
"""Run when entity about to be added to hass."""
await super().async_added_to_hass()
@ -93,13 +102,6 @@ class LcnOutputLight(LcnEntity, LightEntity):
if not self.device_connection.is_group:
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
def brightness(self) -> int | None:
"""Return the brightness of this light between 0..255."""
@ -167,6 +169,9 @@ class LcnOutputLight(LcnEntity, LightEntity):
class LcnRelayLight(LcnEntity, LightEntity):
"""Representation of a LCN light for relay ports."""
_attr_color_mode = COLOR_MODE_ONOFF
_attr_supported_color_modes = {COLOR_MODE_ONOFF}
def __init__(
self, config: ConfigType, entry_id: str, device_connection: DeviceConnectionType
) -> None:

View file

@ -8,9 +8,11 @@ from pypck.lcn_defs import RelayStateModifier
from homeassistant.components.lcn.helpers import get_device_connection
from homeassistant.components.light import (
ATTR_BRIGHTNESS,
ATTR_SUPPORTED_COLOR_MODES,
ATTR_TRANSITION,
COLOR_MODE_BRIGHTNESS,
COLOR_MODE_ONOFF,
DOMAIN as DOMAIN_LIGHT,
SUPPORT_BRIGHTNESS,
SUPPORT_TRANSITION,
)
from homeassistant.const import (
@ -42,14 +44,13 @@ async def test_entity_state(hass, lcn_connection):
"""Test state of entity."""
state = hass.states.get("light.light_output1")
assert state
assert (
state.attributes[ATTR_SUPPORTED_FEATURES]
== SUPPORT_BRIGHTNESS | SUPPORT_TRANSITION
)
assert state.attributes[ATTR_SUPPORTED_FEATURES] == SUPPORT_TRANSITION
assert state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [COLOR_MODE_BRIGHTNESS]
state = hass.states.get("light.light_output2")
assert state
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):