Skip to content

Commit

Permalink
0.9.11
Browse files Browse the repository at this point in the history
  • Loading branch information
jneilliii committed Feb 9, 2019
1 parent 28d941c commit bbb1df3
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 43 deletions.
10 changes: 10 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
16 changes: 14 additions & 2 deletions octoprint_tplinksmartplug/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down
71 changes: 39 additions & 32 deletions octoprint_tplinksmartplug/static/js/tplinksmartplug.js
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -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();
}
});
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<div id="tplinksmartplugs" class="row-fluid" data-bind="foreach: arrSmartplugs">
<!-- ko if: emeter.get_realtime -->
<div class="row-fluid" data-bind="css: currentState()">
Plug: <strong data-bind="text: label"></strong><br/>
Current Power: <strong data-bind="text: $parent.get_power($data)"></strong> W<br/>
Total Consumption: <strong data-bind="text: $parent.get_kwh($data)"></strong> kWh
</div>
<!-- /ko -->
<div id="tplinksmartplugs" class="row-fluid" data-bind="foreach: filteredSmartplugs">
<div class="row-fluid" data-bind="css: currentState()">
Plug: <strong data-bind="text: label"></strong><br/>
Current Power: <strong data-bind="text: $parent.get_power($data)"></strong> W<br/>
Total Consumption: <strong data-bind="text: $parent.get_kwh($data)"></strong> kWh
</div>
</div>
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
plugin_name = "OctoPrint-TPLinkSmartplug"

# The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module
plugin_version = "0.9.10"
plugin_version = "0.9.11"

# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
# module
Expand Down

0 comments on commit bbb1df3

Please sign in to comment.