Yeelight disable polling (#59885)

Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
starkillerOG 2021-11-19 16:02:07 +01:00 committed by GitHub
parent 14d4a9a69d
commit 2b7bcd6aeb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 2 deletions

View file

@ -322,7 +322,7 @@ async def async_setup_entry(
device.name,
)
async_add_entities(lights, True)
async_add_entities(lights)
_async_setup_services(hass)
@ -411,6 +411,7 @@ class YeelightGenericLight(YeelightEntity, LightEntity):
_attr_color_mode = COLOR_MODE_BRIGHTNESS
_attr_supported_color_modes = {COLOR_MODE_BRIGHTNESS}
_attr_should_poll = False
def __init__(self, device, entry, custom_effects=None):
"""Initialize the Yeelight light."""
@ -591,7 +592,7 @@ class YeelightGenericLight(YeelightEntity, LightEntity):
async def async_update(self):
"""Update light properties."""
await self.device.async_update()
await self.device.async_update(True)
async def async_set_music_mode(self, music_mode) -> None:
"""Set the music mode on or off."""

View file

@ -21,6 +21,7 @@ from homeassistant.const import (
CONF_HOST,
CONF_ID,
CONF_NAME,
STATE_ON,
STATE_UNAVAILABLE,
)
from homeassistant.core import HomeAssistant
@ -530,12 +531,14 @@ async def test_connection_dropped_resyncs_properties(hass: HomeAssistant):
assert len(mocked_bulb.async_get_properties.mock_calls) == 1
mocked_bulb._async_callback({KEY_CONNECTED: False})
await hass.async_block_till_done()
assert hass.states.get("light.test_name").state == STATE_UNAVAILABLE
assert len(mocked_bulb.async_get_properties.mock_calls) == 1
mocked_bulb._async_callback({KEY_CONNECTED: True})
async_fire_time_changed(
hass, dt_util.utcnow() + timedelta(seconds=STATE_CHANGE_TIME)
)
await hass.async_block_till_done()
assert hass.states.get("light.test_name").state == STATE_ON
assert len(mocked_bulb.async_get_properties.mock_calls) == 2