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 <arksine.code@gmail.com>
This commit is contained in:
parent
f6fa093369
commit
47c7cea5a5
|
@ -15,16 +15,16 @@ class PrinterPower:
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
self.server = config.get_server()
|
self.server = config.get_server()
|
||||||
self.server.register_endpoint(
|
self.server.register_endpoint(
|
||||||
"/machine/gpio_power/devices", ['GET'],
|
"/machine/device_power/devices", ['GET'],
|
||||||
self._handle_list_devices)
|
self._handle_list_devices)
|
||||||
self.server.register_endpoint(
|
self.server.register_endpoint(
|
||||||
"/machine/gpio_power/status", ['GET'],
|
"/machine/device_power/status", ['GET'],
|
||||||
self._handle_power_request)
|
self._handle_power_request)
|
||||||
self.server.register_endpoint(
|
self.server.register_endpoint(
|
||||||
"/machine/gpio_power/on", ['POST'],
|
"/machine/device_power/on", ['POST'],
|
||||||
self._handle_power_request)
|
self._handle_power_request)
|
||||||
self.server.register_endpoint(
|
self.server.register_endpoint(
|
||||||
"/machine/gpio_power/off", ['POST'],
|
"/machine/device_power/off", ['POST'],
|
||||||
self._handle_power_request)
|
self._handle_power_request)
|
||||||
self.server.register_remote_method(
|
self.server.register_remote_method(
|
||||||
"set_device_power", self.set_device_power)
|
"set_device_power", self.set_device_power)
|
||||||
|
@ -35,7 +35,12 @@ class PrinterPower:
|
||||||
prefix_sections = config.get_prefix_sections("power")
|
prefix_sections = config.get_prefix_sections("power")
|
||||||
logging.info(f"Power plugin loading devices: {prefix_sections}")
|
logging.info(f"Power plugin loading devices: {prefix_sections}")
|
||||||
for section in 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
|
self.devices[dev.get_name()] = dev
|
||||||
|
|
||||||
async def _handle_list_devices(self, web_request):
|
async def _handle_list_devices(self, web_request):
|
||||||
|
|
Loading…
Reference in New Issue