Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions homeassistant/components/lcn/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
from homeassistant.components.light import (
ATTR_BRIGHTNESS,
ATTR_TRANSITION,
COLOR_MODE_BRIGHTNESS,
COLOR_MODE_ONOFF,
DOMAIN as DOMAIN_LIGHT,
SUPPORT_BRIGHTNESS,
SUPPORT_TRANSITION,
LightEntity,
)
Expand Down Expand Up @@ -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:
Expand All @@ -81,6 +84,12 @@ def __init__(
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()
Expand All @@ -93,13 +102,6 @@ async def async_will_remove_from_hass(self) -> None:
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."""
Expand Down Expand Up @@ -167,6 +169,9 @@ def input_received(self, input_obj: InputType) -> None:
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:
Expand Down
11 changes: 6 additions & 5 deletions tests/components/lcn/test_light.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
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 (
Expand Down Expand Up @@ -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):
Expand Down