From 2b7bcd6aeb9e111ca2f74b50fe23d3d1e41aa86d Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Fri, 19 Nov 2021 16:02:07 +0100 Subject: [PATCH] Yeelight disable polling (#59885) Co-authored-by: J. Nick Koston --- homeassistant/components/yeelight/light.py | 5 +++-- tests/components/yeelight/test_init.py | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/yeelight/light.py b/homeassistant/components/yeelight/light.py index ca2752a7a7d..838e56f5d99 100644 --- a/homeassistant/components/yeelight/light.py +++ b/homeassistant/components/yeelight/light.py @@ -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.""" diff --git a/tests/components/yeelight/test_init.py b/tests/components/yeelight/test_init.py index 7e9958a09d2..39e31aa91cf 100644 --- a/tests/components/yeelight/test_init.py +++ b/tests/components/yeelight/test_init.py @@ -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