Skip to content

Commit eefab75

Browse files
authored
Correct color mode when effect active in Wiz (home-assistant#156742)
1 parent 81b4122 commit eefab75

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

homeassistant/components/wiz/light.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,13 @@ def __init__(self, wiz_data: WizData, name: str) -> None:
9999
def _async_update_attrs(self) -> None:
100100
"""Handle updating _attr values."""
101101
state = self._device.state
102-
color_modes = self.supported_color_modes
103-
assert color_modes is not None
102+
104103
if (brightness := state.get_brightness()) is not None:
105104
self._attr_brightness = max(0, min(255, brightness))
105+
106+
color_modes = self.supported_color_modes
107+
assert color_modes is not None
108+
106109
if ColorMode.COLOR_TEMP in color_modes and (
107110
color_temp := state.get_colortemp()
108111
):
@@ -111,12 +114,19 @@ def _async_update_attrs(self) -> None:
111114
elif (
112115
ColorMode.RGBWW in color_modes and (rgbww := state.get_rgbww()) is not None
113116
):
114-
self._attr_rgbww_color = rgbww
115117
self._attr_color_mode = ColorMode.RGBWW
118+
self._attr_rgbww_color = rgbww
116119
elif ColorMode.RGBW in color_modes and (rgbw := state.get_rgbw()) is not None:
117-
self._attr_rgbw_color = rgbw
118120
self._attr_color_mode = ColorMode.RGBW
119-
self._attr_effect = state.get_scene()
121+
self._attr_rgbw_color = rgbw
122+
123+
self._attr_effect = effect = state.get_scene()
124+
if effect is not None:
125+
if brightness is not None:
126+
self._attr_color_mode = ColorMode.BRIGHTNESS
127+
else:
128+
self._attr_color_mode = ColorMode.ONOFF
129+
120130
super()._async_update_attrs()
121131

122132
async def async_turn_on(self, **kwargs: Any) -> None:

tests/components/wiz/test_light.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from homeassistant.components.light import (
66
ATTR_BRIGHTNESS,
7+
ATTR_COLOR_MODE,
78
ATTR_COLOR_TEMP_KELVIN,
89
ATTR_EFFECT,
910
ATTR_RGBW_COLOR,
@@ -109,17 +110,35 @@ async def test_rgbww_light(hass: HomeAssistant) -> None:
109110
await hass.services.async_call(
110111
LIGHT_DOMAIN,
111112
SERVICE_TURN_ON,
112-
{ATTR_ENTITY_ID: entity_id, ATTR_EFFECT: "Ocean"},
113+
{ATTR_ENTITY_ID: entity_id, ATTR_EFFECT: "Ocean", ATTR_BRIGHTNESS: 128},
113114
blocking=True,
114115
)
115116
pilot: PilotBuilder = bulb.turn_on.mock_calls[0][1][0]
116-
assert pilot.pilot_params == {"sceneId": 1}
117+
assert pilot.pilot_params == {"dimming": 50, "sceneId": 1}
117118
await async_push_update(
118119
hass, bulb, {"mac": FAKE_MAC, "state": True, **pilot.pilot_params}
119120
)
120121
state = hass.states.get(entity_id)
121122
assert state.state == STATE_ON
122123
assert state.attributes[ATTR_EFFECT] == "Ocean"
124+
assert state.attributes[ATTR_COLOR_MODE] == "brightness"
125+
126+
bulb.turn_on.reset_mock()
127+
await hass.services.async_call(
128+
LIGHT_DOMAIN,
129+
SERVICE_TURN_ON,
130+
{ATTR_ENTITY_ID: entity_id, ATTR_EFFECT: "Forest"},
131+
blocking=True,
132+
)
133+
pilot: PilotBuilder = bulb.turn_on.mock_calls[0][1][0]
134+
assert pilot.pilot_params == {"sceneId": 7}
135+
await async_push_update(
136+
hass, bulb, {"mac": FAKE_MAC, "state": True, **pilot.pilot_params}
137+
)
138+
state = hass.states.get(entity_id)
139+
assert state.state == STATE_ON
140+
assert state.attributes[ATTR_EFFECT] == "Forest"
141+
assert state.attributes[ATTR_COLOR_MODE] == "onoff"
123142

124143
bulb.turn_on.reset_mock()
125144
await hass.services.async_call(

0 commit comments

Comments
 (0)