mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Correct color mode when effect active in Wiz (#156742)
This commit is contained in:
@@ -99,10 +99,13 @@ class WizBulbEntity(WizToggleEntity, LightEntity):
|
||||
def _async_update_attrs(self) -> None:
|
||||
"""Handle updating _attr values."""
|
||||
state = self._device.state
|
||||
color_modes = self.supported_color_modes
|
||||
assert color_modes is not None
|
||||
|
||||
if (brightness := state.get_brightness()) is not None:
|
||||
self._attr_brightness = max(0, min(255, brightness))
|
||||
|
||||
color_modes = self.supported_color_modes
|
||||
assert color_modes is not None
|
||||
|
||||
if ColorMode.COLOR_TEMP in color_modes and (
|
||||
color_temp := state.get_colortemp()
|
||||
):
|
||||
@@ -111,12 +114,19 @@ class WizBulbEntity(WizToggleEntity, LightEntity):
|
||||
elif (
|
||||
ColorMode.RGBWW in color_modes and (rgbww := state.get_rgbww()) is not None
|
||||
):
|
||||
self._attr_rgbww_color = rgbww
|
||||
self._attr_color_mode = ColorMode.RGBWW
|
||||
self._attr_rgbww_color = rgbww
|
||||
elif ColorMode.RGBW in color_modes and (rgbw := state.get_rgbw()) is not None:
|
||||
self._attr_rgbw_color = rgbw
|
||||
self._attr_color_mode = ColorMode.RGBW
|
||||
self._attr_effect = state.get_scene()
|
||||
self._attr_rgbw_color = rgbw
|
||||
|
||||
self._attr_effect = effect = state.get_scene()
|
||||
if effect is not None:
|
||||
if brightness is not None:
|
||||
self._attr_color_mode = ColorMode.BRIGHTNESS
|
||||
else:
|
||||
self._attr_color_mode = ColorMode.ONOFF
|
||||
|
||||
super()._async_update_attrs()
|
||||
|
||||
async def async_turn_on(self, **kwargs: Any) -> None:
|
||||
|
||||
@@ -4,6 +4,7 @@ from pywizlight import PilotBuilder
|
||||
|
||||
from homeassistant.components.light import (
|
||||
ATTR_BRIGHTNESS,
|
||||
ATTR_COLOR_MODE,
|
||||
ATTR_COLOR_TEMP_KELVIN,
|
||||
ATTR_EFFECT,
|
||||
ATTR_RGBW_COLOR,
|
||||
@@ -109,17 +110,35 @@ async def test_rgbww_light(hass: HomeAssistant) -> None:
|
||||
await hass.services.async_call(
|
||||
LIGHT_DOMAIN,
|
||||
SERVICE_TURN_ON,
|
||||
{ATTR_ENTITY_ID: entity_id, ATTR_EFFECT: "Ocean"},
|
||||
{ATTR_ENTITY_ID: entity_id, ATTR_EFFECT: "Ocean", ATTR_BRIGHTNESS: 128},
|
||||
blocking=True,
|
||||
)
|
||||
pilot: PilotBuilder = bulb.turn_on.mock_calls[0][1][0]
|
||||
assert pilot.pilot_params == {"sceneId": 1}
|
||||
assert pilot.pilot_params == {"dimming": 50, "sceneId": 1}
|
||||
await async_push_update(
|
||||
hass, bulb, {"mac": FAKE_MAC, "state": True, **pilot.pilot_params}
|
||||
)
|
||||
state = hass.states.get(entity_id)
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes[ATTR_EFFECT] == "Ocean"
|
||||
assert state.attributes[ATTR_COLOR_MODE] == "brightness"
|
||||
|
||||
bulb.turn_on.reset_mock()
|
||||
await hass.services.async_call(
|
||||
LIGHT_DOMAIN,
|
||||
SERVICE_TURN_ON,
|
||||
{ATTR_ENTITY_ID: entity_id, ATTR_EFFECT: "Forest"},
|
||||
blocking=True,
|
||||
)
|
||||
pilot: PilotBuilder = bulb.turn_on.mock_calls[0][1][0]
|
||||
assert pilot.pilot_params == {"sceneId": 7}
|
||||
await async_push_update(
|
||||
hass, bulb, {"mac": FAKE_MAC, "state": True, **pilot.pilot_params}
|
||||
)
|
||||
state = hass.states.get(entity_id)
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes[ATTR_EFFECT] == "Forest"
|
||||
assert state.attributes[ATTR_COLOR_MODE] == "onoff"
|
||||
|
||||
bulb.turn_on.reset_mock()
|
||||
await hass.services.async_call(
|
||||
|
||||
Reference in New Issue
Block a user