From 1caaebe03fad2dbdab2e6d97a6db3d8b320f1497 Mon Sep 17 00:00:00 2001 From: Eric Callahan Date: Mon, 15 Nov 2021 10:59:46 -0500 Subject: [PATCH] power: implement workaround for Homeassistant devices Some devices on the Home Assistant server do not update their internal state immediately after a request returns. Introduce a configurable delay to work around this issue. Signed-off-by: Eric Callahan --- moonraker/components/power.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/moonraker/components/power.py b/moonraker/components/power.py index 16098d7..54a66f3 100644 --- a/moonraker/components/power.py +++ b/moonraker/components/power.py @@ -775,6 +775,7 @@ class HomeAssistant(HTTPDevice): self.device: str = config.get("device") self.token: str = config.get("token") self.domain: str = config.get("domain", "switch") + self.status_delay: float = config.getfloat("status_delay", 1.) async def _send_homeassistant_command(self, command: str @@ -818,6 +819,7 @@ class HomeAssistant(HTTPDevice): async def _send_power_request(self, state: str) -> str: await self._send_homeassistant_command(state) + await asyncio.sleep(self.status_delay) res = await self._send_status_request() return res