mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Ensure flux_led bulbs turn on even if brightness is 0 (#59661)
This commit is contained in:
parent
570f80a73c
commit
c323815760
@ -328,13 +328,21 @@ class FluxLight(FluxEntity, CoordinatorEntity, LightEntity):
|
|||||||
|
|
||||||
async def _async_turn_on(self, **kwargs: Any) -> None:
|
async def _async_turn_on(self, **kwargs: Any) -> None:
|
||||||
"""Turn the specified or all lights on."""
|
"""Turn the specified or all lights on."""
|
||||||
|
if (brightness := kwargs.get(ATTR_BRIGHTNESS)) is None:
|
||||||
|
brightness = self.brightness
|
||||||
|
|
||||||
if not self.is_on:
|
if not self.is_on:
|
||||||
await self._device.async_turn_on()
|
await self._device.async_turn_on()
|
||||||
if not kwargs:
|
if not kwargs:
|
||||||
return
|
return
|
||||||
|
# If the brightness was previously 0, the light
|
||||||
if (brightness := kwargs.get(ATTR_BRIGHTNESS)) is None:
|
# will not turn on unless brightness is at least 1
|
||||||
brightness = self.brightness
|
if not brightness:
|
||||||
|
brightness = 1
|
||||||
|
elif not brightness:
|
||||||
|
# If the device was on and brightness was not
|
||||||
|
# set, it means it was masked by an effect
|
||||||
|
brightness = 255
|
||||||
|
|
||||||
# Handle switch to CCT Color Mode
|
# Handle switch to CCT Color Mode
|
||||||
if ATTR_COLOR_TEMP in kwargs:
|
if ATTR_COLOR_TEMP in kwargs:
|
||||||
|
@ -214,11 +214,26 @@ async def test_rgb_light(hass: HomeAssistant) -> None:
|
|||||||
await async_mock_device_turn_off(hass, bulb)
|
await async_mock_device_turn_off(hass, bulb)
|
||||||
assert hass.states.get(entity_id).state == STATE_OFF
|
assert hass.states.get(entity_id).state == STATE_OFF
|
||||||
|
|
||||||
|
bulb.brightness = 0
|
||||||
|
await hass.services.async_call(
|
||||||
|
LIGHT_DOMAIN,
|
||||||
|
"turn_on",
|
||||||
|
{ATTR_ENTITY_ID: entity_id, ATTR_RGB_COLOR: (10, 10, 30)},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
# If the bulb is off and we are using existing brightness
|
||||||
|
# it has to be at least 1 or the bulb won't turn on
|
||||||
|
bulb.async_set_levels.assert_called_with(10, 10, 30, brightness=1)
|
||||||
|
bulb.async_set_levels.reset_mock()
|
||||||
|
bulb.async_turn_on.reset_mock()
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
LIGHT_DOMAIN, "turn_on", {ATTR_ENTITY_ID: entity_id}, blocking=True
|
LIGHT_DOMAIN, "turn_on", {ATTR_ENTITY_ID: entity_id}, blocking=True
|
||||||
)
|
)
|
||||||
bulb.async_turn_on.assert_called_once()
|
bulb.async_turn_on.assert_called_once()
|
||||||
bulb.async_turn_on.reset_mock()
|
bulb.async_turn_on.reset_mock()
|
||||||
|
await async_mock_device_turn_on(hass, bulb)
|
||||||
|
assert hass.states.get(entity_id).state == STATE_ON
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
LIGHT_DOMAIN,
|
LIGHT_DOMAIN,
|
||||||
@ -229,6 +244,19 @@ async def test_rgb_light(hass: HomeAssistant) -> None:
|
|||||||
bulb.async_set_levels.assert_called_with(255, 0, 0, brightness=100)
|
bulb.async_set_levels.assert_called_with(255, 0, 0, brightness=100)
|
||||||
bulb.async_set_levels.reset_mock()
|
bulb.async_set_levels.reset_mock()
|
||||||
|
|
||||||
|
await hass.services.async_call(
|
||||||
|
LIGHT_DOMAIN,
|
||||||
|
"turn_on",
|
||||||
|
{ATTR_ENTITY_ID: entity_id, ATTR_RGB_COLOR: (10, 10, 30)},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
# If the bulb is on and we are using existing brightness
|
||||||
|
# and brightness was 0 it means we could not read it because
|
||||||
|
# an effect is in progress so we use 255
|
||||||
|
bulb.async_set_levels.assert_called_with(10, 10, 30, brightness=255)
|
||||||
|
bulb.async_set_levels.reset_mock()
|
||||||
|
|
||||||
|
bulb.brightness = 128
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
LIGHT_DOMAIN,
|
LIGHT_DOMAIN,
|
||||||
"turn_on",
|
"turn_on",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user