From 23cbd9075aa234b3c8f875c1a75a1a2a8cc186ef Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 29 Sep 2021 13:49:33 -0500 Subject: [PATCH] Wait for yeelight internal state to change before update after on/off (#56795) --- homeassistant/components/yeelight/light.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/homeassistant/components/yeelight/light.py b/homeassistant/components/yeelight/light.py index 30861fa0001..3f5bb29bab7 100644 --- a/homeassistant/components/yeelight/light.py +++ b/homeassistant/components/yeelight/light.py @@ -1,6 +1,7 @@ """Light platform support for yeelight.""" from __future__ import annotations +import asyncio import logging import math @@ -209,6 +210,9 @@ SERVICE_SCHEMA_SET_AUTO_DELAY_OFF_SCENE = { } +STATE_CHANGE_TIME = 0.25 # seconds + + @callback def _transitions_config_parser(transitions): """Parse transitions config into initialized objects.""" @@ -759,6 +763,7 @@ class YeelightGenericLight(YeelightEntity, LightEntity): await self.async_set_default() # Some devices (mainly nightlights) will not send back the on state so we need to force a refresh + await asyncio.sleep(STATE_CHANGE_TIME) if not self.is_on: await self.device.async_update(True) @@ -778,6 +783,7 @@ class YeelightGenericLight(YeelightEntity, LightEntity): await self._async_turn_off(duration) # Some devices will not send back the off state so we need to force a refresh + await asyncio.sleep(STATE_CHANGE_TIME) if self.is_on: await self.device.async_update(True)