diff --git a/changelog.md b/changelog.md index 2140e94..75c7081 100644 --- a/changelog.md +++ b/changelog.md @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [0.9.11] - 2019-02-09 +### Fixed +- Energy monitoring sidebar not displaying consistently. + +## [0.9.10] - 2018-11-25 +### Changed +- Energy monitoring sidebar text controlled via css style instead of inline element styles to allow control via Themeify. + ## [0.9.9] - 2018-11-20 ### Changed - Changed current status logic checks to resolve potential issues with upcoming bundled force login plugin of OctoPrint 1.3.10. @@ -150,6 +158,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Added - Initial release. +[0.9.9]: https://github.com/jneilliii/OctoPrint-TPLinkSmartplug/tree/0.9.11 +[0.9.9]: https://github.com/jneilliii/OctoPrint-TPLinkSmartplug/tree/0.9.10 [0.9.9]: https://github.com/jneilliii/OctoPrint-TPLinkSmartplug/tree/0.9.9 [0.9.8]: https://github.com/jneilliii/OctoPrint-TPLinkSmartplug/tree/0.9.8 [0.9.7]: https://github.com/jneilliii/OctoPrint-TPLinkSmartplug/tree/0.9.7 diff --git a/octoprint_tplinksmartplug/__init__.py b/octoprint_tplinksmartplug/__init__.py index 2233297..1f01de9 100644 --- a/octoprint_tplinksmartplug/__init__.py +++ b/octoprint_tplinksmartplug/__init__.py @@ -63,7 +63,7 @@ def on_settings_save(self, data): self._tplinksmartplug_logger.setLevel(logging.INFO) def get_settings_version(self): - return 7 + return 8 def on_settings_migrate(self, target, current=None): if current is None or current < 5: @@ -82,6 +82,18 @@ def on_settings_migrate(self, target, current=None): self._logger.info("to") self._logger.info(arrSmartplugs_new) self._settings.set(["arrSmartplugs"],arrSmartplugs_new) + elif current == 7: + # Loop through plug array and set emeter to None + arrSmartplugs_new = [] + for plug in self._settings.get(['arrSmartplugs']): + plug["emeter"] = dict(get_realtime = False) + arrSmartplugs_new.append(plug) + + self._logger.info("Updating plug array, converting") + self._logger.info(self._settings.get(['arrSmartplugs'])) + self._logger.info("to") + self._logger.info(arrSmartplugs_new) + self._settings.set(["arrSmartplugs"],arrSmartplugs_new) ##~~ AssetPlugin mixin @@ -197,7 +209,7 @@ def on_api_command(self, command, data): elif command == 'checkStatus': response = self.check_status("{ip}".format(**data)) else: - response = dict(ip = data.ip, currentState = "unknown", emeter = None) + response = dict(ip = data.ip, currentState = "unknown") return flask.jsonify(response) ##~~ Utilities diff --git a/octoprint_tplinksmartplug/static/js/tplinksmartplug.js b/octoprint_tplinksmartplug/static/js/tplinksmartplug.js index ad86a76..ba2e066 100644 --- a/octoprint_tplinksmartplug/static/js/tplinksmartplug.js +++ b/octoprint_tplinksmartplug/static/js/tplinksmartplug.js @@ -15,15 +15,13 @@ $(function() { self.isPrinting = ko.observable(false); self.selectedPlug = ko.observable(); self.processing = ko.observableArray([]); - self.show_sidebar = ko.computed(function(){ - var energy_monitoring_enabled = ko.utils.arrayFilter(self.arrSmartplugs(), function(item) { - if (item.emeter){ - return "get_realtime" in item.emeter; - } else { - return false; - } + self.filteredSmartplugs = ko.computed(function(){ + return ko.utils.arrayFilter(self.arrSmartplugs(), function(item) { + return "err_code" in item.emeter.get_realtime; }); - return energy_monitoring_enabled.length > 0; + }); + self.show_sidebar = ko.computed(function(){ + return self.filteredSmartplugs().length > 0; }); self.get_power = function(data){ // make computedObservable()? if("power" in data.emeter.get_realtime){ @@ -75,29 +73,29 @@ $(function() { self.addPlug = function() { self.selectedPlug({'ip':ko.observable(''), - 'label':ko.observable(''), - 'icon':ko.observable('icon-bolt'), - 'displayWarning':ko.observable(true), - 'warnPrinting':ko.observable(false), - 'gcodeEnabled':ko.observable(false), - 'gcodeOnDelay':ko.observable(0), - 'gcodeOffDelay':ko.observable(0), - 'autoConnect':ko.observable(true), - 'autoConnectDelay':ko.observable(10.0), - 'autoDisconnect':ko.observable(true), - 'autoDisconnectDelay':ko.observable(0), - 'sysCmdOn':ko.observable(false), - 'sysRunCmdOn':ko.observable(''), - 'sysCmdOnDelay':ko.observable(0), - 'sysCmdOff':ko.observable(false), - 'sysRunCmdOff':ko.observable(''), - 'sysCmdOffDelay':ko.observable(0), - 'currentState':ko.observable('unknown'), - 'btnColor':ko.observable('#808080'), - 'useCountdownRules':ko.observable(false), - 'countdownOnDelay':ko.observable(0), - 'countdownOffDelay':ko.observable(0), - 'emeter':ko.observable()}); + 'label':ko.observable(''), + 'icon':ko.observable('icon-bolt'), + 'displayWarning':ko.observable(true), + 'warnPrinting':ko.observable(false), + 'gcodeEnabled':ko.observable(false), + 'gcodeOnDelay':ko.observable(0), + 'gcodeOffDelay':ko.observable(0), + 'autoConnect':ko.observable(true), + 'autoConnectDelay':ko.observable(10.0), + 'autoDisconnect':ko.observable(true), + 'autoDisconnectDelay':ko.observable(0), + 'sysCmdOn':ko.observable(false), + 'sysRunCmdOn':ko.observable(''), + 'sysCmdOnDelay':ko.observable(0), + 'sysCmdOff':ko.observable(false), + 'sysRunCmdOff':ko.observable(''), + 'sysCmdOffDelay':ko.observable(0), + 'currentState':ko.observable('unknown'), + 'btnColor':ko.observable('#808080'), + 'useCountdownRules':ko.observable(false), + 'countdownOnDelay':ko.observable(0), + 'countdownOffDelay':ko.observable(0), + 'emeter':{get_realtime:{}}}); self.settings.settings.plugins.tplinksmartplug.arrSmartplugs.push(self.selectedPlug()); $("#TPLinkPlugEditor").modal("show"); } @@ -214,17 +212,26 @@ $(function() { }).done(function(data){ // self.settings.saveData(); console.log(data); + var saveNeeded = false; ko.utils.arrayForEach(self.arrSmartplugs(),function(item){ + console.log(item); if(item.ip() == data.ip) { item.currentState(data.currentState); if(data.emeter){ + item.emeter.get_realtime = {}; for (key in data.emeter.get_realtime){ console.log(key + ' = ' + data.emeter.get_realtime[key]); - item.emeter.get_realtime[key](data.emeter.get_realtime[key]); + item.emeter.get_realtime[key] = ko.observable(data.emeter.get_realtime[key]); } + saveNeeded = true; } + self.processing.remove(data.ip); } }); + if (saveNeeded) { + self.settings.settings.plugins.tplinksmartplug.arrSmartplugs(self.arrSmartplugs()); + self.settings.saveData(); + } }); }; diff --git a/octoprint_tplinksmartplug/templates/tplinksmartplug_sidebar.jinja2 b/octoprint_tplinksmartplug/templates/tplinksmartplug_sidebar.jinja2 index 3552a93..cf97d71 100644 --- a/octoprint_tplinksmartplug/templates/tplinksmartplug_sidebar.jinja2 +++ b/octoprint_tplinksmartplug/templates/tplinksmartplug_sidebar.jinja2 @@ -1,9 +1,7 @@ -