diff --git a/README.md b/README.md index 3e220ad..4ae71c2 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,8 @@ Work inspired by [OctoPrint-PSUControl](https://github.com/kantlivelong/OctoPrin ![screenshot](settings.png) +![screenshot](plugeditor.png) + ## Setup Install via the bundled [Plugin Manager](https://github.com/foosel/OctoPrint/wiki/Plugin:-Plugin-Manager) @@ -20,7 +22,12 @@ or manually using this URL: Once installed go into settings and enter the ip address for your TP-Link Smartplug device. Adjust additional settings as needed. ## Settings Explained - +- **IP** + - IP or hostname of plug to control. +- **Label** + - Label to use for title attribute on hover over button in navbar. +- **Icon Class** + - Class name from [fontawesome](http://fontawesome.io/3.2.1/cheatsheet/) to use for icon on button. - **Warn** - The left checkbox will always warn when checked. - The right checkbox will only warn when printer is printing. diff --git a/changelog.md b/changelog.md index 7d81335..2dd28de 100644 --- a/changelog.md +++ b/changelog.md @@ -4,6 +4,18 @@ 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.0] - 2018-01-30 +### Notes +- **Previously configured plugs will be erased upon upgrade to account for new data structure.** + +### Added +- Button labeling. +- Button icons configurable via fontawesome class names found [here](http://fontawesome.io/3.2.1/cheatsheet/). +- Spinning icon while awaiting response from server. + +### Changed +- Improved settings layout, less clutter. + ## [0.8.0] - 2018-01-29 ### Added - Status polling of all configured plugs. @@ -92,6 +104,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Added - Initial release. +[0.9.0]: https://github.com/jneilliii/OctoPrint-TPLinkSmartplug/tree/0.9.0 [0.8.0]: https://github.com/jneilliii/OctoPrint-TPLinkSmartplug/tree/0.8.0 [0.7.3]: https://github.com/jneilliii/OctoPrint-TPLinkSmartplug/tree/0.7.3 [0.7.2]: https://github.com/jneilliii/OctoPrint-TPLinkSmartplug/tree/0.7.2 diff --git a/octoprint_tplinksmartplug/__init__.py b/octoprint_tplinksmartplug/__init__.py index d77d8b0..7e7264e 100644 --- a/octoprint_tplinksmartplug/__init__.py +++ b/octoprint_tplinksmartplug/__init__.py @@ -42,7 +42,7 @@ def on_after_startup(self): def get_settings_defaults(self): return dict( debug_logging = False, - arrSmartplugs = [{'ip':'','displayWarning':True,'warnPrinting':False,'gcodeEnabled':False,'gcodeOnDelay':0,'gcodeOffDelay':0,'autoConnect':True,'autoConnectDelay':10.0,'autoDisconnect':True,'autoDisconnectDelay':0,'sysCmdOn':False,'sysRunCmdOn':'','sysCmdOnDelay':0,'sysCmdOff':False,'sysRunCmdOff':'','sysCmdOffDelay':0,'currentState':'unknown','btnColor':'#808080'}], + arrSmartplugs = [{'ip':'','label':'','icon':'icon-bolt','displayWarning':True,'warnPrinting':False,'gcodeEnabled':False,'gcodeOnDelay':0,'gcodeOffDelay':0,'autoConnect':True,'autoConnectDelay':10.0,'autoDisconnect':True,'autoDisconnectDelay':0,'sysCmdOn':False,'sysRunCmdOn':'','sysCmdOnDelay':0,'sysCmdOff':False,'sysRunCmdOff':'','sysCmdOffDelay':0,'currentState':'unknown','btnColor':'#808080'}], pollingInterval = 15, pollingEnabled = False ) @@ -60,7 +60,7 @@ def on_settings_save(self, data): self._tplinksmartplug_logger.setLevel(logging.INFO) def get_settings_version(self): - return 3 + return 4 def on_settings_migrate(self, target, current=None): if current is None or current < self.get_settings_version(): @@ -72,7 +72,8 @@ def on_settings_migrate(self, target, current=None): def get_assets(self): return dict( - js=["js/tplinksmartplug.js"] + js=["js/tplinksmartplug.js"], + css=["css/tplinksmartplug.css"] ) ##~~ TemplatePlugin mixin diff --git a/octoprint_tplinksmartplug/static/css/tplinksmartplug.css b/octoprint_tplinksmartplug/static/css/tplinksmartplug.css new file mode 100644 index 0000000..fd2f699 --- /dev/null +++ b/octoprint_tplinksmartplug/static/css/tplinksmartplug.css @@ -0,0 +1,16 @@ +#navbar_plugin_tplinksmartplug > a > i.on { + color: #00FF00 !important; +} + +#navbar_plugin_tplinksmartplug > a > i.off { + color: #FF0000 !important; +} + +#navbar_plugin_tplinksmartplug > a > i.unknown { + color: #808080 !important; +} + +#TPLinkPlugEditor table th, #TPLinkPlugEditor table td { + border-top: none; + vertical-align: top; +} \ No newline at end of file diff --git a/octoprint_tplinksmartplug/static/js/tplinksmartplug.js b/octoprint_tplinksmartplug/static/js/tplinksmartplug.js index 5365d33..d733236 100644 --- a/octoprint_tplinksmartplug/static/js/tplinksmartplug.js +++ b/octoprint_tplinksmartplug/static/js/tplinksmartplug.js @@ -13,6 +13,8 @@ $(function() { self.arrSmartplugs = ko.observableArray(); self.isPrinting = ko.observable(false); + self.selectedPlug = ko.observable(); + self.processing = ko.observableArray([]); self.onBeforeBinding = function() { self.arrSmartplugs(self.settings.settings.plugins.tplinksmartplug.arrSmartplugs()); @@ -23,7 +25,6 @@ $(function() { } self.onEventSettingsUpdated = function(payload) { - self.settings.requestData(); self.arrSmartplugs(self.settings.settings.plugins.tplinksmartplug.arrSmartplugs()); } @@ -35,8 +36,19 @@ $(function() { } } + self.cancelClick = function(data) { + self.processing.remove(data.ip()); + } + + self.editPlug = function(data) { + self.selectedPlug(data); + $("#TPLinkPlugEditor").modal("show"); + } + self.addPlug = function() { - self.settings.settings.plugins.tplinksmartplug.arrSmartplugs.push({'ip':ko.observable(''), + 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), @@ -54,6 +66,8 @@ $(function() { 'sysCmdOffDelay':ko.observable(0), 'currentState':ko.observable('unknown'), 'btnColor':ko.observable('#808080')}); + self.settings.settings.plugins.tplinksmartplug.arrSmartplugs.push(self.selectedPlug); + $("#TPLinkPlugEditor").modal("show"); } self.removePlug = function(row) { @@ -73,13 +87,10 @@ $(function() { plug.currentState(data.currentState) switch(data.currentState) { case "on": - plug.btnColor("#00FF00"); break; case "off": - plug.btnColor("#FF0000"); break; default: - plug.btnColor("#808080"); new PNotify({ title: 'TP-Link Smartplug Error', text: 'Status ' + plug.currentState() + ' for ' + plug.ip() + '. Double check IP Address\\Hostname in TPLinkSmartplug Settings.', @@ -89,9 +100,11 @@ $(function() { self.settings.saveData(); } } + self.processing.remove(data.ip); }; self.toggleRelay = function(data) { + self.processing.push(data.ip()); switch(data.currentState()){ case "on": self.turnOff(data); @@ -125,11 +138,11 @@ $(function() { }; self.turnOff = function(data) { - var dlg_id = "#tplinksmartplug_poweroff_confirmation_dialog_" + data.ip().replace( /(:|\.|[|])/g, "\\$1" ); - if((data.displayWarning() || (self.isPrinting() && data.warnPrinting())) && !$(dlg_id).is(':visible')){ - $(dlg_id).modal("show"); + if((data.displayWarning() || (self.isPrinting() && data.warnPrinting())) && !$("#TPLinkSmartPlugWarning").is(':visible')){ + self.selectedPlug(data); + $("#TPLinkSmartPlugWarning").modal("show"); } else { - $(dlg_id).modal("hide"); + $("#TPLinkSmartPlugWarning").modal("hide"); if(data.sysCmdOff()){ setTimeout(function(){self.sysCommand(data.sysRunCmdOff())},data.sysCmdOffDelay()*1000); } diff --git a/octoprint_tplinksmartplug/templates/tplinksmartplug_navbar.jinja2 b/octoprint_tplinksmartplug/templates/tplinksmartplug_navbar.jinja2 index 069af70..e6e4d5d 100644 --- a/octoprint_tplinksmartplug/templates/tplinksmartplug_navbar.jinja2 +++ b/octoprint_tplinksmartplug/templates/tplinksmartplug_navbar.jinja2 @@ -1,23 +1,22 @@ - - -