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/homematicip_cloud/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
ATTR_COLOR_NAME,
ATTR_HS_COLOR,
ATTR_TRANSITION,
SUPPORT_BRIGHTNESS,
SUPPORT_COLOR,
COLOR_MODE_BRIGHTNESS,
COLOR_MODE_HS,
COLOR_MODE_ONOFF,
SUPPORT_TRANSITION,
LightEntity,
)
Expand Down Expand Up @@ -70,6 +71,9 @@ async def async_setup_entry(
class HomematicipLight(HomematicipGenericEntity, LightEntity):
"""Representation of the HomematicIP light."""

_attr_color_mode = COLOR_MODE_ONOFF
_attr_supported_color_modes = {COLOR_MODE_ONOFF}

def __init__(self, hap: HomematicipHAP, device) -> None:
"""Initialize the light entity."""
super().__init__(hap, device)
Expand All @@ -95,6 +99,9 @@ class HomematicipLightMeasuring(HomematicipLight):
class HomematicipMultiDimmer(HomematicipGenericEntity, LightEntity):
"""Representation of HomematicIP Cloud dimmer."""

_attr_color_mode = COLOR_MODE_BRIGHTNESS
_attr_supported_color_modes = {COLOR_MODE_BRIGHTNESS}

def __init__(
self,
hap: HomematicipHAP,
Expand All @@ -120,11 +127,6 @@ def brightness(self) -> int:
(self._device.functionalChannels[self._channel].dimLevel or 0.0) * 255
)

@property
def supported_features(self) -> int:
"""Flag supported features."""
return SUPPORT_BRIGHTNESS

async def async_turn_on(self, **kwargs) -> None:
"""Turn the dimmer on."""
if ATTR_BRIGHTNESS in kwargs:
Expand All @@ -150,6 +152,9 @@ def __init__(self, hap: HomematicipHAP, device) -> None:
class HomematicipNotificationLight(HomematicipGenericEntity, LightEntity):
"""Representation of HomematicIP Cloud notification light."""

_attr_color_mode = COLOR_MODE_HS
_attr_supported_color_modes = {COLOR_MODE_HS}

def __init__(self, hap: HomematicipHAP, device, channel: int) -> None:
"""Initialize the notification light entity."""
if channel == 2:
Expand Down Expand Up @@ -207,7 +212,7 @@ def extra_state_attributes(self) -> dict[str, Any]:
@property
def supported_features(self) -> int:
"""Flag supported features."""
return SUPPORT_BRIGHTNESS | SUPPORT_COLOR | SUPPORT_TRANSITION
return SUPPORT_TRANSITION

@property
def unique_id(self) -> str:
Expand Down
38 changes: 37 additions & 1 deletion tests/components/homematicip_cloud/test_light.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@
from homeassistant.components.homematicip_cloud import DOMAIN as HMIPC_DOMAIN
from homeassistant.components.light import (
ATTR_BRIGHTNESS,
ATTR_COLOR_MODE,
ATTR_COLOR_NAME,
ATTR_SUPPORTED_COLOR_MODES,
COLOR_MODE_BRIGHTNESS,
COLOR_MODE_HS,
COLOR_MODE_ONOFF,
DOMAIN as LIGHT_DOMAIN,
SUPPORT_TRANSITION,
)
from homeassistant.const import STATE_OFF, STATE_ON
from homeassistant.const import ATTR_SUPPORTED_FEATURES, STATE_OFF, STATE_ON
from homeassistant.setup import async_setup_component

from .helper import async_manipulate_test_data, get_and_check_entity_basics
Expand Down Expand Up @@ -35,6 +41,9 @@ async def test_hmip_light(hass, default_mock_hap_factory):
)

assert ha_state.state == STATE_ON
assert ha_state.attributes[ATTR_COLOR_MODE] == COLOR_MODE_ONOFF
assert ha_state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [COLOR_MODE_ONOFF]
assert ha_state.attributes[ATTR_SUPPORTED_FEATURES] == 0

service_call_counter = len(hmip_device.mock_calls)
await hass.services.async_call(
Expand All @@ -47,6 +56,9 @@ async def test_hmip_light(hass, default_mock_hap_factory):
await async_manipulate_test_data(hass, hmip_device, "on", False)
ha_state = hass.states.get(entity_id)
assert ha_state.state == STATE_OFF
assert ATTR_COLOR_MODE not in ha_state.attributes
assert ha_state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [COLOR_MODE_ONOFF]
assert ha_state.attributes[ATTR_SUPPORTED_FEATURES] == 0

await hass.services.async_call(
"light", "turn_on", {"entity_id": entity_id}, blocking=True
Expand Down Expand Up @@ -74,6 +86,9 @@ async def test_hmip_notification_light(hass, default_mock_hap_factory):
)

assert ha_state.state == STATE_OFF
assert ATTR_COLOR_MODE not in ha_state.attributes
assert ha_state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [COLOR_MODE_HS]
assert ha_state.attributes[ATTR_SUPPORTED_FEATURES] == SUPPORT_TRANSITION
service_call_counter = len(hmip_device.mock_calls)

# Send all color via service call.
Expand Down Expand Up @@ -128,6 +143,9 @@ async def test_hmip_notification_light(hass, default_mock_hap_factory):
assert ha_state.state == STATE_ON
assert ha_state.attributes[ATTR_COLOR_NAME] == RGBColorState.PURPLE
assert ha_state.attributes[ATTR_BRIGHTNESS] == 255
assert ha_state.attributes[ATTR_COLOR_MODE] == COLOR_MODE_HS
assert ha_state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [COLOR_MODE_HS]
assert ha_state.attributes[ATTR_SUPPORTED_FEATURES] == SUPPORT_TRANSITION

await hass.services.async_call(
"light", "turn_off", {"entity_id": entity_id, "transition": 100}, blocking=True
Expand Down Expand Up @@ -165,6 +183,9 @@ async def test_hmip_dimmer(hass, default_mock_hap_factory):
)

assert ha_state.state == STATE_OFF
assert ATTR_COLOR_MODE not in ha_state.attributes
assert ha_state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [COLOR_MODE_BRIGHTNESS]
assert ha_state.attributes[ATTR_SUPPORTED_FEATURES] == 0
service_call_counter = len(hmip_device.mock_calls)

await hass.services.async_call(
Expand All @@ -186,6 +207,9 @@ async def test_hmip_dimmer(hass, default_mock_hap_factory):
ha_state = hass.states.get(entity_id)
assert ha_state.state == STATE_ON
assert ha_state.attributes[ATTR_BRIGHTNESS] == 255
assert ha_state.attributes[ATTR_COLOR_MODE] == COLOR_MODE_BRIGHTNESS
assert ha_state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [COLOR_MODE_BRIGHTNESS]
assert ha_state.attributes[ATTR_SUPPORTED_FEATURES] == 0

await hass.services.async_call(
"light", "turn_off", {"entity_id": entity_id}, blocking=True
Expand Down Expand Up @@ -217,6 +241,9 @@ async def test_hmip_light_measuring(hass, default_mock_hap_factory):
)

assert ha_state.state == STATE_OFF
assert ATTR_COLOR_MODE not in ha_state.attributes
assert ha_state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [COLOR_MODE_ONOFF]
assert ha_state.attributes[ATTR_SUPPORTED_FEATURES] == 0
service_call_counter = len(hmip_device.mock_calls)

await hass.services.async_call(
Expand All @@ -229,6 +256,9 @@ async def test_hmip_light_measuring(hass, default_mock_hap_factory):
await async_manipulate_test_data(hass, hmip_device, "currentPowerConsumption", 50)
ha_state = hass.states.get(entity_id)
assert ha_state.state == STATE_ON
assert ha_state.attributes[ATTR_COLOR_MODE] == COLOR_MODE_ONOFF
assert ha_state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [COLOR_MODE_ONOFF]
assert ha_state.attributes[ATTR_SUPPORTED_FEATURES] == 0

await hass.services.async_call(
"light", "turn_off", {"entity_id": entity_id}, blocking=True
Expand All @@ -255,6 +285,9 @@ async def test_hmip_wired_multi_dimmer(hass, default_mock_hap_factory):
)

assert ha_state.state == STATE_OFF
assert ATTR_COLOR_MODE not in ha_state.attributes
assert ha_state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [COLOR_MODE_BRIGHTNESS]
assert ha_state.attributes[ATTR_SUPPORTED_FEATURES] == 0
service_call_counter = len(hmip_device.mock_calls)

await hass.services.async_call(
Expand All @@ -276,6 +309,9 @@ async def test_hmip_wired_multi_dimmer(hass, default_mock_hap_factory):
ha_state = hass.states.get(entity_id)
assert ha_state.state == STATE_ON
assert ha_state.attributes[ATTR_BRIGHTNESS] == 255
assert ha_state.attributes[ATTR_COLOR_MODE] == COLOR_MODE_BRIGHTNESS
assert ha_state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [COLOR_MODE_BRIGHTNESS]
assert ha_state.attributes[ATTR_SUPPORTED_FEATURES] == 0

await hass.services.async_call(
"light", "turn_off", {"entity_id": entity_id}, blocking=True
Expand Down