From af00afa3f9eed8a497dd33ea6b72615e1387dd79 Mon Sep 17 00:00:00 2001 From: Kyle Gabriel Date: Fri, 15 Dec 2023 19:55:18 -0500 Subject: [PATCH] Improve Neokey 4x1 Function, update changelog --- CHANGELOG.md | 13 ++++++----- .../functions/function_adafruit_neokey_01.py | 22 ++++++++++++++----- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ebdb4eb1a..735d617c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,20 +1,23 @@ ## 8.15.13 (Unreleased) -### Features +### Bugfixes - Fix inability to properly import settings backup + - Fix Actions not executing for MQTT, TTN, and Python Code Inputs ([#1336](https://github.com/kizniche/Mycodo/issues/1336)) + - Fix running pylint + +### Features + - Add ability to use Actions in Custom Functions - Add Input Action: Execute Python 3 Code ([#1334](https://github.com/kizniche/Mycodo/issues/1334)) - Add Function: Adafruit Neokey (Key Press Executes Actions) ([#1353](https://github.com/kizniche/Mycodo/issues/1353)) - Add Action: Neopixel Flashing On - Add Action: Neopixel Flashing Off - Change deprecated threading.currentThread to threading.current_thread - - Update InfluxDB 2.x to 2.7.3 -### Bugfixes +### Miscellaneous - - Fix Actions not executing for MQTT, TTN, and Python Code Inputs ([#1336](https://github.com/kizniche/Mycodo/issues/1336)) - - Fix running pylint + - Update InfluxDB 2.x to 2.7.3 ## 8.15.12 (2023.10.28) diff --git a/mycodo/functions/function_adafruit_neokey_01.py b/mycodo/functions/function_adafruit_neokey_01.py index a89a86e43..518c4bda5 100644 --- a/mycodo/functions/function_adafruit_neokey_01.py +++ b/mycodo/functions/function_adafruit_neokey_01.py @@ -243,6 +243,14 @@ def execute_at_modification( 'required': True, 'name': 'Last Action LED Color (RGB)', 'phrase': 'The RGB color while the last action is running (e.g 10, 0, 0)' + }, + { + 'id': 'led_shutdown', + 'type': 'text', + 'default_value': '0, 0, 0', + 'required': True, + 'name': 'Shutdown LED Color (RGB)', + 'phrase': 'The RGB color when the Function is disabled (e.g 10, 0, 0)' } ] } @@ -260,7 +268,7 @@ def __init__(self, function, testing=False): self.flashing = {} self.colorwheel = None self.control = None - self.timer_flash = None + self.timer_flash = time.time() self.key_press_executing = {} self.toggle = {} @@ -336,14 +344,11 @@ def listener(self): while self.running: # Check key press for key in range(4): - if self.neokey[key]: + if self.neokey[key] and not self.key_press_executing[key]: self.key_press_executing[key] = True self.logger.debug(f"Key {key + 1} Pressed") self.set_color({"led_number": key, "led_color": self.options_channels['led_start'][key]}) - while self.neokey[key] and self.running: - time.sleep(0.2) - write_influxdb_value( self.unique_id, self.channels_measurement[key].unit, @@ -369,7 +374,12 @@ def listener(self): self.flashing[key]["on"] = True self.set_color({"led_number": key, "led_color": self.flashing[key]["color"]}) - time.sleep(0.25) + time.sleep(0.05) + + def stop_function(self): + self.running = False + for key in range(4): + self.set_color({"led_number": key, "led_color": self.options_channels['led_shutdown'][key]}) def run_key_actions(self, key): action_ids = self.options_channels['key_action_ids'][key]