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:
parent
06bea715a3
commit
cb8e5af8f7
|
@ -111,8 +111,12 @@ class PrinterPower:
|
||||||
return result
|
return result
|
||||||
|
|
||||||
async def _process_request(self, device, req):
|
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"]:
|
if req in ["on", "off"]:
|
||||||
cur_state = device.get_device_info()['status']
|
cur_state = dev_info['status']
|
||||||
if req == cur_state:
|
if req == cur_state:
|
||||||
# device is already in requested state, do nothing
|
# device is already in requested state, do nothing
|
||||||
return cur_state
|
return cur_state
|
||||||
|
@ -127,12 +131,7 @@ class PrinterPower:
|
||||||
dev_info = device.get_device_info()
|
dev_info = device.get_device_info()
|
||||||
self.server.send_event("power:power_changed", dev_info)
|
self.server.send_event("power:power_changed", dev_info)
|
||||||
device.run_power_changed_action()
|
device.run_power_changed_action()
|
||||||
elif req == "status":
|
elif req != "status":
|
||||||
ret = device.refresh_status()
|
|
||||||
if asyncio.iscoroutine(ret):
|
|
||||||
await ret
|
|
||||||
dev_info = device.get_device_info()
|
|
||||||
else:
|
|
||||||
raise self.server.error(f"Unsupported power request: {req}")
|
raise self.server.error(f"Unsupported power request: {req}")
|
||||||
return dev_info['status']
|
return dev_info['status']
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue