diff --git a/octoprint_tasmota/__init__.py b/octoprint_tasmota/__init__.py index f23cac7..86702ff 100644 --- a/octoprint_tasmota/__init__.py +++ b/octoprint_tasmota/__init__.py @@ -225,7 +225,7 @@ def on_settings_save(self, data): self.poll_status.start() def get_settings_version(self): - return 10 + return 11 def on_settings_migrate(self, target, current=None): if current is None or current < 6: @@ -261,6 +261,14 @@ def on_settings_migrate(self, target, current=None): plug["event_on_connecting"] = False arrSmartplugs_new.append(plug) self._settings.set(["arrSmartplugs"], arrSmartplugs_new) + if current < 11: + # Add new fields + arrSmartplugs_new = [] + for plug in self._settings.get(['arrSmartplugs']): + plug["is_led"] = False + plug["brightness"] = 50 + arrSmartplugs_new.append(plug) + self._settings.set(["arrSmartplugs"], arrSmartplugs_new) ##~~ AssetPlugin mixin @@ -676,6 +684,18 @@ def gcode_off(self, plug): def gcode_on(self, plug): self.turn_on(plug["ip"], plug["idx"]) + def gcode_led(self, plugip, led_data): + self._tasmota_logger.debug("Received LED Command for {} with parameters {}".format(plugip, led_data)) + for plug in self._settings.get(["arrSmartplugs"]): + if plug["is_led"]: + if led_data["LEDBrightness"] == -1: + led_data["LEDBrightness"] = plug["brightness"] + try: + requests.get("http://{}/cm".format(plugip), params={"user": plug["username"], "password": plug["password"], "cmnd": "backlog dimmer {}; color2 {},{},{}; white {}; power{} on".format(led_data["LEDBrightness"], led_data["LEDRed"], led_data["LEDGreen"], led_data["LEDBlue"], led_data["LEDWhite"], plug["idx"])}, timeout=3) + self._plugin_manager.send_plugin_message(self._identifier, dict(currentState="on", ip=plug["ip"], idx=plug["idx"], color=led_data)) + except Exception as e: + self._logger.debug("Error: {}".format(e)) + def processGCODE(self, comm_instance, phase, cmd, cmd_type, gcode, *args, **kwargs): if gcode: if gcode in ["M80", "M81"] and cmd.count(" ") >= 2: @@ -699,6 +719,36 @@ def processGCODE(self, comm_instance, phase, cmd, cmd_type, gcode, *args, **kwar return else: return + elif gcode == "M150": + workleds = dict(LEDRed=0, LEDBlue=0, LEDGreen=0, LEDWhite=0, LEDBrightness=-1) + workval = cmd.upper().split() + for i in workval: + firstchar = str(i[0].upper()) + leddata = str(i[1:].strip()) + if not leddata.isdigit() and firstchar != 'I': + self._tasmota_logger.debug(leddata) + return + + if firstchar == 'M': + continue + elif firstchar == "I": + plugip = leddata + elif firstchar == 'R': + workleds['LEDRed'] = int(leddata) + elif firstchar == 'G' or firstchar == 'U': + workleds['LEDGreen'] = int(leddata) + elif firstchar == 'B': + workleds['LEDBlue'] = int(leddata) + elif firstchar == "W": + workleds['LEDWhite'] = int(float(leddata)/255*100) + elif firstchar == "P": + workleds['LEDBrightness'] = int(float(leddata)/255*100) + else: + self._tasmota_logger.debug(leddata) + + t = threading.Timer(0, self.gcode_led, [plugip, workleds]) + t.daemon = True + t.start() elif self.powerOffWhenIdle and not (gcode in self._idleIgnoreCommandsArray): self._waitForHeaters = False self._reset_idle_timer() diff --git a/octoprint_tasmota/static/css/tasmota.css b/octoprint_tasmota/static/css/tasmota.css index 84d991a..dd73348 100644 --- a/octoprint_tasmota/static/css/tasmota.css +++ b/octoprint_tasmota/static/css/tasmota.css @@ -72,3 +72,8 @@ input[type="datetime-local"].alert-error { background-color: #f2dede; border-color: #b94a48; } + +#TasmotaEditor input[type=checkbox] { + margin-top: 0px; + vertical-align: baseline; +} diff --git a/octoprint_tasmota/static/js/tasmota.js b/octoprint_tasmota/static/js/tasmota.js index 9eb06ec..a2e783b 100644 --- a/octoprint_tasmota/static/js/tasmota.js +++ b/octoprint_tasmota/static/js/tasmota.js @@ -15,6 +15,7 @@ $(function() { self.arrSmartplugs = ko.observableArray(); self.arrSmartplugsTooltips = ko.observableDictionary({}); self.arrSmartplugsStates = ko.observableDictionary({}); + self.arrSmartplugsLEDColors = ko.observableDictionary({}); self.isPrinting = ko.observable(false); self.gcodeOnString = function(data){return 'M80 '+data.ip()+' '+data.idx();}; self.gcodeOffString = function(data){return 'M81 '+data.ip()+' '+data.idx();}; @@ -23,9 +24,9 @@ $(function() { self.get_color = function(data){ switch(self.arrSmartplugsStates.get(data.ip()+'_'+data.idx())()) { case "on": - return data.on_color(); + return self.arrSmartplugsLEDColors.get(data.ip()+'_'+data.idx())() ? self.arrSmartplugsLEDColors.get(data.ip()+'_'+data.idx())() : data.on_color(); case "off": - return data.off_color(); + return self.arrSmartplugsLEDColors.get(data.ip()+'_'+data.idx())() ? data.unknown_color() : data.off_color(); default: return data.unknown_color(); } @@ -386,7 +387,7 @@ $(function() { var tooltip = plug.label(); if(data.sensor_data) { for(k in data.sensor_data) { - tooltip += '
' + k + ': ' + data.sensor_data[k] + tooltip += '
' + k + ': ' + data.sensor_data["k"] } } if(data.energy_data) { @@ -403,7 +404,7 @@ $(function() { } try { self.arrSmartplugsStates.set(data.ip + '_' + data.idx, data.currentState); - }catch (error) { + } catch (error) { self.processing.remove(data.ip); console.log('currentState', error); } @@ -415,6 +416,10 @@ $(function() { hide: true }); } + if(data.color){ + var color = (data.color.LEDBrightness > 0) ? 'RGB(' + data.color.LEDRed + ',' + data.color.LEDGreen + ',' + data.color.LEDBlue + ')' : plug["unknown_color"]; + self.arrSmartplugsLEDColors.set(data.ip + '_' + data.idx, color); + } self.processing.remove(data.ip); } }; diff --git a/octoprint_tasmota/templates/tasmota_settings.jinja2 b/octoprint_tasmota/templates/tasmota_settings.jinja2 index eae943c..8c9c30d 100644 --- a/octoprint_tasmota/templates/tasmota_settings.jinja2 +++ b/octoprint_tasmota/templates/tasmota_settings.jinja2 @@ -213,7 +213,7 @@
- +
%
@@ -221,8 +221,8 @@
-
-
+
+
diff --git a/setup.py b/setup.py index c683fd3..629596f 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ plugin_name = "OctoPrint-Tasmota" # The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module -plugin_version = "1.0.2rc3" +plugin_version = "1.0.2rc4" # The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin # module