From cb8e5af8f7307ed77462fca3f90d5e68b346be65 Mon Sep 17 00:00:00 2001 From: Arksine Date: Sun, 9 May 2021 19:36:31 -0400 Subject: [PATCH] power: always refresh status prior to processing a request Make sure that the current device state is correct in the event that a device is toggled by an external source. Signed-off-by: Eric Callahan --- moonraker/components/power.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/moonraker/components/power.py b/moonraker/components/power.py index 4cd883b..1f1107b 100644 --- a/moonraker/components/power.py +++ b/moonraker/components/power.py @@ -111,8 +111,12 @@ class PrinterPower: return result async def _process_request(self, device, req): + ret = device.refresh_status() + if asyncio.iscoroutine(ret): + await ret + dev_info = device.get_device_info() if req in ["on", "off"]: - cur_state = device.get_device_info()['status'] + cur_state = dev_info['status'] if req == cur_state: # device is already in requested state, do nothing return cur_state @@ -127,12 +131,7 @@ class PrinterPower: dev_info = device.get_device_info() self.server.send_event("power:power_changed", dev_info) device.run_power_changed_action() - elif req == "status": - ret = device.refresh_status() - if asyncio.iscoroutine(ret): - await ret - dev_info = device.get_device_info() - else: + elif req != "status": raise self.server.error(f"Unsupported power request: {req}") return dev_info['status']