Wait for yeelight internal state to change before update after on/off (#56795)

pull/56800/head
J. Nick Koston 2021-09-29 13:49:33 -05:00 committed by GitHub
parent 25ce7f951a
commit 23cbd9075a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 0 deletions

View File

@ -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)