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 <arksine.code@gmail.com>
This commit is contained in:
Arksine committed 2021-05-09 19:36:58 -04:00
1 parent 06bea715a3
commit cb8e5af8f7
1 file changed
+6 -7
+6 -7
View File
@@ -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']