power: update request handlers to accept WebRequest objects

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Arksine 2020-11-09 07:02:22 -05:00
parent 6c8ef93f9f
commit de1575f757
1 changed files with 6 additions and 4 deletions

View File

@ -38,7 +38,7 @@ class PrinterPower:
ioloop = IOLoop.current() ioloop = IOLoop.current()
ioloop.spawn_callback(self.initialize_devices, devices) ioloop.spawn_callback(self.initialize_devices, devices)
async def _handle_list_devices(self, path, method, args): async def _handle_list_devices(self, web_request):
output = {"devices": []} output = {"devices": []}
for dev in self.devices: for dev in self.devices:
output['devices'].append({ output['devices'].append({
@ -47,15 +47,17 @@ class PrinterPower:
}) })
return output return output
async def _handle_power_request(self, path, method, args): async def _handle_power_request(self, web_request):
args = web_request.get_args()
ep = web_request.get_endpoint()
if len(args) == 0: if len(args) == 0:
if path == "/machine/gpio_power/status": if ep == "/machine/gpio_power/status":
args = self.devices args = self.devices
else: else:
return "no_devices" return "no_devices"
result = {} result = {}
req = path.split("/")[-1] req = ep.split("/")[-1]
for dev in args: for dev in args:
if req not in ("on", "off", "status"): if req not in ("on", "off", "status"):
raise self.server.error("Unsupported power request") raise self.server.error("Unsupported power request")