Skip to content

Commit c6c7854

Browse files
authored
1.0.3
2 parents a87d584 + 63ff8b7 commit c6c7854

9 files changed

+91
-93
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
***Warning***: Recent firmware version 1.1.0 for the HS100, HS110 have been reported to break the capability of this plugin to communicate with kasa devices. So far it seems to be only effecting UK version plugs, but could spread to other firmware variants.
44

5-
***Warning***: Recent firmware updates for the HS103 breaks the use of this plugin with those devices. TP-Link may push the same firmware to other devices, but be warned that updating your devices firmware may break the use of this plugin. It appears this can be resolved by never connecting the plug to the cloud by following the steps outlined [here](https://www.tp-link.com/us/support/faq/2707/).
5+
***Warning***: Recent firmware updates for the HS103 breaks the use of this plugin with those devices. TP-Link may push the same firmware to other devices, but be warned that updating your devices firmware may break the use of this plugin. It appears this can be resolved by never connecting the plug to the cloud by following the steps outlined [here](https://github.com/jneilliii/OctoPrint-TPLinkSmartplug/tree/master/extras/How_to_make_Kasa_smart_devices_controlled_local_only.pdf).
66

77
Work inspired by [OctoPrint-PSUControl](https://github.com/kantlivelong/OctoPrint-PSUControl) and [TP-Link WiFi SmartPlug Client](https://github.com/softScheck/tplink-smartplug), this plugin controls a TP-Link Smartplug via OctoPrint's nav bar. Currently known compatible models are the HS100, HS103, HS105, HS107, HS110, HS300, KP105, KP303, KP115. Other Kasa app based devices may work. Tapo series devices will not work with this plugin, and probably never will because of their closed communication.
88

@@ -29,7 +29,7 @@ Once installed go into settings and enter the ip address for your TP-Link Smartp
2929

3030
## Settings Explained
3131
- **IP**
32-
- IP or hostname of plug to control. For strip devices use the format `<ip>/<0 based socket index>`, ie 192.168.0.2/0 would control the first socket in the strip.
32+
- IP or hostname of plug to control. For strip devices use the format `<ip>/<1 based socket index>`, ie 192.168.0.2/1 would control the first socket in the strip.
3333
- **Label**
3434
- Label to use for title attribute on hover over button in navbar.
3535
- **Icon Class**
Binary file not shown.

octoprint_tplinksmartplug/__init__.py

+18-31
Original file line numberDiff line numberDiff line change
@@ -162,28 +162,13 @@ def on_after_startup(self):
162162
##~~ SettingsPlugin mixin
163163

164164
def get_settings_defaults(self):
165-
return dict(
166-
debug_logging=False,
167-
arrSmartplugs=[],
168-
pollingInterval=15,
169-
pollingEnabled=False,
170-
thermal_runaway_monitoring=False,
171-
thermal_runaway_max_bed=0,
172-
thermal_runaway_max_extruder=0,
173-
event_on_error_monitoring=False,
174-
event_on_disconnect_monitoring=False,
175-
event_on_upload_monitoring=False,
176-
event_on_upload_monitoring_always=False,
177-
event_on_startup_monitoring=False,
178-
event_on_shutdown_monitoring=False,
179-
cost_rate=0,
180-
abortTimeout=30,
181-
powerOffWhenIdle=False,
182-
idleTimeout=30,
183-
idleIgnoreCommands='M105',
184-
idleTimeoutWaitTemp=50,
185-
progress_polling=False
186-
)
165+
return {'debug_logging': False, 'arrSmartplugs': [], 'pollingInterval': 15, 'pollingEnabled': False,
166+
'thermal_runaway_monitoring': False, 'thermal_runaway_max_bed': 0, 'thermal_runaway_max_extruder': 0,
167+
'event_on_error_monitoring': False, 'event_on_disconnect_monitoring': False,
168+
'event_on_upload_monitoring': False, 'event_on_upload_monitoring_always': False,
169+
'event_on_startup_monitoring': False, 'event_on_shutdown_monitoring': False, 'cost_rate': 0,
170+
'abortTimeout': 30, 'powerOffWhenIdle': False, 'idleTimeout': 30, 'idleIgnoreCommands': 'M105',
171+
'idleTimeoutWaitTemp': 50, 'progress_polling': False, 'useDropDown': False}
187172

188173
def on_settings_save(self, data):
189174
old_debug_logging = self._settings.get_boolean(["debug_logging"])
@@ -353,13 +338,14 @@ def get_assets(self):
353338
##~~ TemplatePlugin mixin
354339

355340
def get_template_configs(self):
356-
templates_to_load = [dict(type="navbar", custom_bindings=True), dict(type="settings", custom_bindings=True),
357-
dict(type="sidebar", icon="plug", custom_bindings=True,
358-
data_bind="visible: arrSmartplugs().length > 0",
359-
template="tplinksmartplug_sidebar.jinja2",
360-
template_header="tplinksmartplug_sidebar_header.jinja2"),
361-
dict(type="tab", custom_bindings=True, data_bind="visible: show_sidebar()",
362-
template="tplinksmartplug_tab.jinja2")]
341+
templates_to_load = [{'type': "navbar", 'custom_bindings': True, 'classes': ["dropdown"]},
342+
{'type': "settings", 'custom_bindings': True},
343+
{'type': "sidebar", 'icon': "plug", 'custom_bindings': True,
344+
'data_bind': "visible: arrSmartplugs().length > 0",
345+
'template': "tplinksmartplug_sidebar.jinja2",
346+
'template_header': "tplinksmartplug_sidebar_header.jinja2"},
347+
{'type': "tab", 'custom_bindings': True, 'data_bind': "visible: show_sidebar()",
348+
'template': "tplinksmartplug_tab.jinja2"}]
363349
return templates_to_load
364350

365351
##~~ ProgressPlugin mixin
@@ -760,7 +746,8 @@ def on_event(self, event, payload):
760746
self._autostart_file = None
761747
# File Uploaded Event
762748
if event == Events.UPLOAD and self._settings.get_boolean(["event_on_upload_monitoring"]):
763-
if payload.get("print", False) or self._settings.get_boolean(["event_on_upload_monitoring_always"]): # implemented in OctoPrint version 1.4.1
749+
if payload.get("print", False) or self._settings.get_boolean(
750+
["event_on_upload_monitoring_always"]): # implemented in OctoPrint version 1.4.1
764751
self._tplinksmartplug_logger.debug(
765752
"File uploaded: %s. Turning enabled plugs on." % payload.get("name", ""))
766753
self._tplinksmartplug_logger.debug(payload)
@@ -1154,7 +1141,7 @@ def processAtCommand(self, comm_instance, phase, command, parameters, tags=None,
11541141

11551142
def check_temps(self, parsed_temps):
11561143
thermal_runaway_triggered = False
1157-
for k, v in parsed_temps.items():
1144+
for k, v in list(parsed_temps.items()):
11581145
if k == "B" and v[0] > int(self._settings.get(["thermal_runaway_max_bed"])):
11591146
self._tplinksmartplug_logger.debug("Max bed temp reached, shutting off plugs.")
11601147
thermal_runaway_triggered = True

octoprint_tplinksmartplug/static/css/tplinksmartplug.css

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
#navbar_plugin_tplinksmartplug > a > i.on {
1+
#navbar_plugin_tplinksmartplug > a > i.on,
2+
#navbar_plugin_tplinksmartplug > ul > li > a > i.on
3+
{
24
color: #00FF00 !important;
35
}
46

5-
#navbar_plugin_tplinksmartplug > a > i.off {
7+
#navbar_plugin_tplinksmartplug > a > i.off,
8+
#navbar_plugin_tplinksmartplug > ul > li > a > i.off
9+
{
610
color: #FF0000 !important;
711
}
812

octoprint_tplinksmartplug/static/js/plotly-latest.min.js

+30-26
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

octoprint_tplinksmartplug/static/js/tplinksmartplug.js

+9-29
Original file line numberDiff line numberDiff line change
@@ -12,38 +12,18 @@ $(function() {
1212
self.loginState = parameters[1];
1313
self.filesViewModel = parameters[2];
1414

15+
// Hijack the getAdditionalData function and add the custom data
16+
let oldGetData = self.filesViewModel.getAdditionalData;
1517
self.filesViewModel.getAdditionalData = function(data) {
16-
var output = "";
17-
if (data["gcodeAnalysis"]) {
18-
if (data["gcodeAnalysis"]["dimensions"]) {
19-
var dimensions = data["gcodeAnalysis"]["dimensions"];
20-
output += gettext("Model size") + ": " + _.sprintf("%(width).2fmm &times; %(depth).2fmm &times; %(height).2fmm", dimensions);
21-
output += "<br>";
22-
}
23-
if (data["gcodeAnalysis"]["filament"] && typeof(data["gcodeAnalysis"]["filament"]) === "object") {
24-
var filament = data["gcodeAnalysis"]["filament"];
25-
if (_.keys(filament).length === 1) {
26-
output += gettext("Filament") + ": " + formatFilament(data["gcodeAnalysis"]["filament"]["tool" + 0]) + "<br>";
27-
} else if (_.keys(filament).length > 1) {
28-
_.each(filament, function(f, k) {
29-
if (!_.startsWith(k, "tool") || !f || !f.hasOwnProperty("length") || f["length"] <= 0) return;
30-
output += gettext("Filament") + " (" + gettext("Tool") + " " + k.substr("tool".length)
31-
+ "): " + formatFilament(f) + "<br>";
32-
});
33-
}
34-
}
35-
output += gettext("Estimated print time") + ": " + (self.settings.appearance_fuzzyTimes() ? formatFuzzyPrintTime(data["gcodeAnalysis"]["estimatedPrintTime"]) : formatDuration(data["gcodeAnalysis"]["estimatedPrintTime"])) + "<br>";
36-
}
37-
if (data["prints"] && data["prints"]["last"]) {
38-
output += gettext("Last printed") + ": " + formatTimeAgo(data["prints"]["last"]["date"]) + "<br>";
39-
if (data["prints"]["last"]["printTime"]) {
40-
output += gettext("Last print time") + ": " + formatDuration(data["prints"]["last"]["printTime"]) + "<br>";
41-
}
42-
}
18+
var returnStr = "" + oldGetData(data);
19+
if (!returnStr.endsWith('<br>')) {
20+
returnStr = returnStr + "<br>";
21+
}
22+
4323
if (data["statistics"] && data["statistics"]["lastPowerCost"]) {
44-
output += gettext("Last power cost") + ": " + data["statistics"]["lastPowerCost"]["_default"] + "<br>";
24+
returnStr += gettext("Last power cost") + ": " + data["statistics"]["lastPowerCost"]["_default"] + "<br>";
4525
}
46-
return output;
26+
return returnStr;
4727
};
4828

4929
self.arrSmartplugs = ko.observableArray();

octoprint_tplinksmartplug/templates/tplinksmartplug_navbar.jinja2

+16-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
1+
<!-- ko if: settings.settings.plugins.tplinksmartplug.useDropDown -->
2+
<a href="javascript:void(0)" title="TPLink SmartPlugs" class="dropdown-toggle" data-toggle="dropdown">
3+
<i class="fa fa-plug"></i>
4+
<b class="caret"></b>
5+
</a>
6+
<ul class="dropdown-menu" data-bind="foreach: arrSmartplugs">
7+
<li>
8+
<a href="#" data-toggle="tooltip" data-html="true" data-bind="click: $root.toggleRelay, visible: $root.loginState.loggedIn(), tooltip: {title: label, placement: 'bottom'}"><i class="icon" data-bind="css: [currentState(), icon(),(($root.processing().indexOf(ip()) > -1) ? 'icon-spin' : '')].join(' ')"></i> <span data-bind="text: label"></span></a>
9+
</li>
10+
</ul>
11+
<!-- /ko -->
12+
<!-- ko if: !(settings.settings.plugins.tplinksmartplug.useDropDown()) -->
113
<!-- ko foreach: arrSmartplugs -->
2-
<a class="pull-right" href="#" data-toggle="tooltip" data-html="true" data-bind="click: $root.toggleRelay, visible: $root.loginState.loggedIn(), tooltip: {title: label, placement: 'bottom'}" style="float: left;"><i class="icon" data-bind="css: [currentState(), icon(),(($root.processing().indexOf(ip()) > -1) ? 'icon-spin' : '')].join(' ')"></i><span data-bind="text: label"></span></a>
14+
<a class="pull-right" href="#" data-toggle="tooltip" data-html="true" data-bind="click: $root.toggleRelay, visible: $root.loginState.loggedIn(), tooltip: {title: label, placement: 'bottom'}" style="float: left;"><i class="icon" data-bind="css: [currentState(), icon(),(($root.processing().indexOf(ip()) > -1) ? 'icon-spin' : '')].join(' ')"></i><span data-bind="text: label"></span></a>
15+
<!-- /ko -->
316
<!-- /ko -->
417

18+
519
<div id="TPLinkSmartPlugWarning" data-bind="with: selectedPlug" class="modal hide fade">
620
<div class="modal-header">
721
<a href="#" class="close" data-dismiss="modal" aria-hidden="true">&times;</a>
822
<h3>TP-Link Smartplug</h3>
923
</div>
1024
<div class="modal-body">
1125
<p>
12-
<!--ko text: label()--><!--/ko--> is currently <!--ko text: currentState()--><!--/ko-->.
26+
<!--ko text: label()--><!--/ko--> is currently <!--ko text: currentState()--><!--/ko-->.
1327
</p>
1428
<p>
1529
{{ _('Are you sure you want to proceed?') }}

octoprint_tplinksmartplug/templates/tplinksmartplug_settings.jinja2

+9
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,15 @@
191191
</div>
192192
</div>
193193
</div>
194+
<div class="row-fluid">
195+
<div class="control-group">
196+
<div class="controls">
197+
<label class="checkbox">
198+
<input type="checkbox" title="{{ _('Put all control buttons in a drop-down menu.') }}" data-toggle="tooltip" data-bind="checked: settings.settings.plugins.tplinksmartplug.useDropDown, tooltip: {}" /> {{ _('Use Drop Down Menu') }}
199+
</label>
200+
</div>
201+
</div>
202+
</div>
194203
</div>
195204
</div>
196205
<div class="row-fluid">

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
plugin_name = "OctoPrint-TPLinkSmartplug"
1515

1616
# The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module
17-
plugin_version = "1.0.2"
17+
plugin_version = "1.0.3"
1818

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

0 commit comments

Comments
 (0)