mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Fix yeelight brightness when nightlight switch is disabled (#55278)
This commit is contained in:
parent
ae1d2926cf
commit
c3972b22fd
@ -859,7 +859,12 @@ class YeelightColorLightWithoutNightlightSwitch(
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def _brightness_property(self):
|
def _brightness_property(self):
|
||||||
return "current_brightness"
|
# If the nightlight is not active, we do not
|
||||||
|
# want to "current_brightness" since it will check
|
||||||
|
# "bg_power" and main light could still be on
|
||||||
|
if self.device.is_nightlight_enabled:
|
||||||
|
return "current_brightness"
|
||||||
|
return super()._brightness_property
|
||||||
|
|
||||||
|
|
||||||
class YeelightColorLightWithNightlightSwitch(
|
class YeelightColorLightWithNightlightSwitch(
|
||||||
@ -883,7 +888,12 @@ class YeelightWhiteTempWithoutNightlightSwitch(
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def _brightness_property(self):
|
def _brightness_property(self):
|
||||||
return "current_brightness"
|
# If the nightlight is not active, we do not
|
||||||
|
# want to "current_brightness" since it will check
|
||||||
|
# "bg_power" and main light could still be on
|
||||||
|
if self.device.is_nightlight_enabled:
|
||||||
|
return "current_brightness"
|
||||||
|
return super()._brightness_property
|
||||||
|
|
||||||
|
|
||||||
class YeelightWithNightLight(
|
class YeelightWithNightLight(
|
||||||
|
@ -96,6 +96,7 @@ from homeassistant.util.color import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
from . import (
|
from . import (
|
||||||
|
CAPABILITIES,
|
||||||
ENTITY_LIGHT,
|
ENTITY_LIGHT,
|
||||||
ENTITY_NIGHTLIGHT,
|
ENTITY_NIGHTLIGHT,
|
||||||
IP_ADDRESS,
|
IP_ADDRESS,
|
||||||
@ -1178,3 +1179,38 @@ async def test_state_fails_to_update_triggers_update(hass: HomeAssistant):
|
|||||||
)
|
)
|
||||||
assert len(mocked_bulb.async_turn_on.mock_calls) == 1
|
assert len(mocked_bulb.async_turn_on.mock_calls) == 1
|
||||||
assert len(mocked_bulb.async_get_properties.mock_calls) == 3
|
assert len(mocked_bulb.async_get_properties.mock_calls) == 3
|
||||||
|
|
||||||
|
|
||||||
|
async def test_ambilight_with_nightlight_disabled(hass: HomeAssistant):
|
||||||
|
"""Test that main light on ambilights with the nightlight disabled shows the correct brightness."""
|
||||||
|
mocked_bulb = _mocked_bulb()
|
||||||
|
properties = {**PROPERTIES}
|
||||||
|
capabilities = {**CAPABILITIES}
|
||||||
|
capabilities["model"] = "ceiling10"
|
||||||
|
properties["color_mode"] = "3" # HSV
|
||||||
|
properties["bg_power"] = "off"
|
||||||
|
properties["current_brightness"] = 0
|
||||||
|
properties["bg_lmode"] = "2" # CT
|
||||||
|
mocked_bulb.last_properties = properties
|
||||||
|
mocked_bulb.bulb_type = BulbType.WhiteTempMood
|
||||||
|
main_light_entity_id = "light.yeelight_ceiling10_0x15243f"
|
||||||
|
|
||||||
|
config_entry = MockConfigEntry(
|
||||||
|
domain=DOMAIN,
|
||||||
|
data={**CONFIG_ENTRY_DATA, CONF_NIGHTLIGHT_SWITCH: False},
|
||||||
|
options={**CONFIG_ENTRY_DATA, CONF_NIGHTLIGHT_SWITCH: False},
|
||||||
|
)
|
||||||
|
config_entry.add_to_hass(hass)
|
||||||
|
with _patch_discovery(capabilities=capabilities), patch(
|
||||||
|
f"{MODULE}.AsyncBulb", return_value=mocked_bulb
|
||||||
|
):
|
||||||
|
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
# We use asyncio.create_task now to avoid
|
||||||
|
# blocking starting so we need to block again
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
state = hass.states.get(main_light_entity_id)
|
||||||
|
assert state.state == "on"
|
||||||
|
# bg_power off should not set the brightness to 0
|
||||||
|
assert state.attributes[ATTR_BRIGHTNESS] == 128
|
||||||
|
Loading…
x
Reference in New Issue
Block a user