From 4f247c47d65a21341d4def4a9ade6cdbd93c3758 Mon Sep 17 00:00:00 2001 From: cp2004 <31997505+cp2004@users.noreply.github.com> Date: Fri, 1 Oct 2021 22:29:36 +0100 Subject: [PATCH] :sparkles: Lights toggle API command --- docs/documentation/rest-api.md | 1 + octoprint_ws281x_led_status/api.py | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/docs/documentation/rest-api.md b/docs/documentation/rest-api.md index 8899ee0..c593a8a 100644 --- a/docs/documentation/rest-api.md +++ b/docs/documentation/rest-api.md @@ -96,6 +96,7 @@ See also the [SimpleApi docs](https://docs.octoprint.org/en/devel/plugins/mixins | :--- | :--- | :--- | | `lights_on` | None | Turn the LEDs on | | `lights_off` | None | Turn the LEDs off | +| `lights_toggle` | None | Toggle the LED state | | `torch_on` | None | Turn the torch mode on | | `torch_off` | None | Turn the torch mode off. Only available if torch mode is configured as toggle. | | `test_os_config` | None | Begin an OS configuration test. Asynchronous, data is returned on the socket | diff --git a/octoprint_ws281x_led_status/api.py b/octoprint_ws281x_led_status/api.py index 79c0b43..8b9970b 100644 --- a/octoprint_ws281x_led_status/api.py +++ b/octoprint_ws281x_led_status/api.py @@ -13,6 +13,7 @@ # Define API commands CMD_LIGHTS_ON = "lights_on" CMD_LIGHTS_OFF = "lights_off" +CMD_LIGHTS_TOGGLE = "lights_toggle" CMD_TORCH_ON = "torch_on" CMD_TORCH_OFF = "torch_off" CMD_TEST_OS = "test_os_config" @@ -33,6 +34,7 @@ def get_api_commands(): return { CMD_LIGHTS_ON: [], CMD_LIGHTS_OFF: [], + CMD_LIGHTS_TOGGLE: [], CMD_TORCH_ON: [], CMD_TORCH_OFF: [], CMD_TEST_OS: [], @@ -49,6 +51,8 @@ def on_api_command(self, command, data): self.plugin.activate_lights() elif command == CMD_LIGHTS_OFF: self.plugin.deactivate_lights() + elif command == CMD_LIGHTS_TOGGLE: + self.plugin.switch_lights(not self.plugin.lights_on) elif command == CMD_TORCH_ON: self.plugin.activate_torch() elif command == CMD_TORCH_OFF: