diff --git a/octoprint_mystromswitch/__init__.py b/octoprint_mystromswitch/__init__.py index b7bd6ab..d914c77 100644 --- a/octoprint_mystromswitch/__init__.py +++ b/octoprint_mystromswitch/__init__.py @@ -62,8 +62,9 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin, try: request = requests.get( 'http://{}/report'.format(self.ip), timeout=1) - self._plugin_manager.send_plugin_message(self._identifier, - request.json()) + data = request.json() + data["onOffButtonEnabled"] = self.onOffButtonEnabled + self._plugin_manager.send_plugin_message(self._identifier, data) except (requests.exceptions.ConnectionError, ValueError): self._logger.info('Connection Error Host: {}'.format(self.ip)) else: diff --git a/octoprint_mystromswitch/static/js/mystromswitch.js b/octoprint_mystromswitch/static/js/mystromswitch.js index b38a543..6e40889 100644 --- a/octoprint_mystromswitch/static/js/mystromswitch.js +++ b/octoprint_mystromswitch/static/js/mystromswitch.js @@ -6,7 +6,7 @@ $(function() { self.settings = parameters[1]; self.printer = parameters[2]; - self.mystromswitchEnabled = ko.observable(); + self.onOffButtonEnabled = ko.observable(); self.mystromswitchPowerValue = document.getElementById("mystromswitchPowerValue") self.onToggleRelayEvent = function(){ @@ -22,7 +22,7 @@ $(function() { } self.onmystromswitchEvent = function() { - if (self.mystromswitchEnabled()) { + if (self.onOffButtonEnabled()) { $.ajax({ url: API_BASEURL + "plugin/mystromswitch", type: "POST", @@ -45,13 +45,13 @@ $(function() { } } - self.mystromswitchEnabled.subscribe(self.onmystromswitchEvent, self); + self.onOffButtonEnabled.subscribe(self.onmystromswitchEvent, self); self.onDataUpdaterPluginMessage = function(plugin, data) { if (plugin != "mystromswitch" && plugin != "octoprint_mystromswitch") { return; } - self.mystromswitchEnabled(data.mystromswitchEnabled); + self.onOffButtonEnabled(data.onOffButtonEnabled); if(data.relay == false){ self.mystromswitchPowerValue.innerHTML = "Relay is off"; } else if (data.power != null) { diff --git a/octoprint_mystromswitch/templates/mystromswitch_sidebar.jinja2 b/octoprint_mystromswitch/templates/mystromswitch_sidebar.jinja2 index b65647e..0dc213f 100644 --- a/octoprint_mystromswitch/templates/mystromswitch_sidebar.jinja2 +++ b/octoprint_mystromswitch/templates/mystromswitch_sidebar.jinja2 @@ -1,4 +1,4 @@