From 47c7cea5a53d51fd909df6baf50082f7e654901d Mon Sep 17 00:00:00 2001 From: Arksine Date: Mon, 16 Nov 2020 08:46:05 -0500 Subject: [PATCH] power: add initial support for device types This changes the API endpoints from "/machine/gpio_power" to "/machine/device_power". Signed-off-by: Eric Callahan --- moonraker/plugins/power.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/moonraker/plugins/power.py b/moonraker/plugins/power.py index c29f8e1..ec7aa5b 100644 --- a/moonraker/plugins/power.py +++ b/moonraker/plugins/power.py @@ -15,16 +15,16 @@ class PrinterPower: def __init__(self, config): self.server = config.get_server() self.server.register_endpoint( - "/machine/gpio_power/devices", ['GET'], + "/machine/device_power/devices", ['GET'], self._handle_list_devices) self.server.register_endpoint( - "/machine/gpio_power/status", ['GET'], + "/machine/device_power/status", ['GET'], self._handle_power_request) self.server.register_endpoint( - "/machine/gpio_power/on", ['POST'], + "/machine/device_power/on", ['POST'], self._handle_power_request) self.server.register_endpoint( - "/machine/gpio_power/off", ['POST'], + "/machine/device_power/off", ['POST'], self._handle_power_request) self.server.register_remote_method( "set_device_power", self.set_device_power) @@ -35,7 +35,12 @@ class PrinterPower: prefix_sections = config.get_prefix_sections("power") logging.info(f"Power plugin loading devices: {prefix_sections}") for section in prefix_sections: - dev = GpioDevice(config[section], self.chip_factory) + cfg = config[section] + dev_type = cfg.get("type") + if dev_type == "gpio": + dev = GpioDevice(cfg, self.chip_factory) + else: + raise config.error(f"Unsupported Device Type: {dev_type}") self.devices[dev.get_name()] = dev async def _handle_list_devices(self, web_request):