Skip to content

Commit

Permalink
1.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
jneilliii authored Mar 18, 2023
2 parents a87d584 + 63ff8b7 commit c6c7854
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 93 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

***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.

***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/).
***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).

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.

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

## Settings Explained
- **IP**
- 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.
- 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.
- **Label**
- Label to use for title attribute on hover over button in navbar.
- **Icon Class**
Expand Down
Binary file not shown.
49 changes: 18 additions & 31 deletions octoprint_tplinksmartplug/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,28 +162,13 @@ def on_after_startup(self):
##~~ SettingsPlugin mixin

def get_settings_defaults(self):
return dict(
debug_logging=False,
arrSmartplugs=[],
pollingInterval=15,
pollingEnabled=False,
thermal_runaway_monitoring=False,
thermal_runaway_max_bed=0,
thermal_runaway_max_extruder=0,
event_on_error_monitoring=False,
event_on_disconnect_monitoring=False,
event_on_upload_monitoring=False,
event_on_upload_monitoring_always=False,
event_on_startup_monitoring=False,
event_on_shutdown_monitoring=False,
cost_rate=0,
abortTimeout=30,
powerOffWhenIdle=False,
idleTimeout=30,
idleIgnoreCommands='M105',
idleTimeoutWaitTemp=50,
progress_polling=False
)
return {'debug_logging': False, 'arrSmartplugs': [], 'pollingInterval': 15, 'pollingEnabled': False,
'thermal_runaway_monitoring': False, 'thermal_runaway_max_bed': 0, 'thermal_runaway_max_extruder': 0,
'event_on_error_monitoring': False, 'event_on_disconnect_monitoring': False,
'event_on_upload_monitoring': False, 'event_on_upload_monitoring_always': False,
'event_on_startup_monitoring': False, 'event_on_shutdown_monitoring': False, 'cost_rate': 0,
'abortTimeout': 30, 'powerOffWhenIdle': False, 'idleTimeout': 30, 'idleIgnoreCommands': 'M105',
'idleTimeoutWaitTemp': 50, 'progress_polling': False, 'useDropDown': False}

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

def get_template_configs(self):
templates_to_load = [dict(type="navbar", custom_bindings=True), dict(type="settings", custom_bindings=True),
dict(type="sidebar", icon="plug", custom_bindings=True,
data_bind="visible: arrSmartplugs().length > 0",
template="tplinksmartplug_sidebar.jinja2",
template_header="tplinksmartplug_sidebar_header.jinja2"),
dict(type="tab", custom_bindings=True, data_bind="visible: show_sidebar()",
template="tplinksmartplug_tab.jinja2")]
templates_to_load = [{'type': "navbar", 'custom_bindings': True, 'classes': ["dropdown"]},
{'type': "settings", 'custom_bindings': True},
{'type': "sidebar", 'icon': "plug", 'custom_bindings': True,
'data_bind': "visible: arrSmartplugs().length > 0",
'template': "tplinksmartplug_sidebar.jinja2",
'template_header': "tplinksmartplug_sidebar_header.jinja2"},
{'type': "tab", 'custom_bindings': True, 'data_bind': "visible: show_sidebar()",
'template': "tplinksmartplug_tab.jinja2"}]
return templates_to_load

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

def check_temps(self, parsed_temps):
thermal_runaway_triggered = False
for k, v in parsed_temps.items():
for k, v in list(parsed_temps.items()):
if k == "B" and v[0] > int(self._settings.get(["thermal_runaway_max_bed"])):
self._tplinksmartplug_logger.debug("Max bed temp reached, shutting off plugs.")
thermal_runaway_triggered = True
Expand Down
8 changes: 6 additions & 2 deletions octoprint_tplinksmartplug/static/css/tplinksmartplug.css
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#navbar_plugin_tplinksmartplug > a > i.on {
#navbar_plugin_tplinksmartplug > a > i.on,
#navbar_plugin_tplinksmartplug > ul > li > a > i.on
{
color: #00FF00 !important;
}

#navbar_plugin_tplinksmartplug > a > i.off {
#navbar_plugin_tplinksmartplug > a > i.off,
#navbar_plugin_tplinksmartplug > ul > li > a > i.off
{
color: #FF0000 !important;
}

Expand Down
56 changes: 30 additions & 26 deletions octoprint_tplinksmartplug/static/js/plotly-latest.min.js

Large diffs are not rendered by default.

38 changes: 9 additions & 29 deletions octoprint_tplinksmartplug/static/js/tplinksmartplug.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,18 @@ $(function() {
self.loginState = parameters[1];
self.filesViewModel = parameters[2];

// Hijack the getAdditionalData function and add the custom data
let oldGetData = self.filesViewModel.getAdditionalData;
self.filesViewModel.getAdditionalData = function(data) {
var output = "";
if (data["gcodeAnalysis"]) {
if (data["gcodeAnalysis"]["dimensions"]) {
var dimensions = data["gcodeAnalysis"]["dimensions"];
output += gettext("Model size") + ": " + _.sprintf("%(width).2fmm &times; %(depth).2fmm &times; %(height).2fmm", dimensions);
output += "<br>";
}
if (data["gcodeAnalysis"]["filament"] && typeof(data["gcodeAnalysis"]["filament"]) === "object") {
var filament = data["gcodeAnalysis"]["filament"];
if (_.keys(filament).length === 1) {
output += gettext("Filament") + ": " + formatFilament(data["gcodeAnalysis"]["filament"]["tool" + 0]) + "<br>";
} else if (_.keys(filament).length > 1) {
_.each(filament, function(f, k) {
if (!_.startsWith(k, "tool") || !f || !f.hasOwnProperty("length") || f["length"] <= 0) return;
output += gettext("Filament") + " (" + gettext("Tool") + " " + k.substr("tool".length)
+ "): " + formatFilament(f) + "<br>";
});
}
}
output += gettext("Estimated print time") + ": " + (self.settings.appearance_fuzzyTimes() ? formatFuzzyPrintTime(data["gcodeAnalysis"]["estimatedPrintTime"]) : formatDuration(data["gcodeAnalysis"]["estimatedPrintTime"])) + "<br>";
}
if (data["prints"] && data["prints"]["last"]) {
output += gettext("Last printed") + ": " + formatTimeAgo(data["prints"]["last"]["date"]) + "<br>";
if (data["prints"]["last"]["printTime"]) {
output += gettext("Last print time") + ": " + formatDuration(data["prints"]["last"]["printTime"]) + "<br>";
}
}
var returnStr = "" + oldGetData(data);
if (!returnStr.endsWith('<br>')) {
returnStr = returnStr + "<br>";
}

if (data["statistics"] && data["statistics"]["lastPowerCost"]) {
output += gettext("Last power cost") + ": " + data["statistics"]["lastPowerCost"]["_default"] + "<br>";
returnStr += gettext("Last power cost") + ": " + data["statistics"]["lastPowerCost"]["_default"] + "<br>";
}
return output;
return returnStr;
};

self.arrSmartplugs = ko.observableArray();
Expand Down
18 changes: 16 additions & 2 deletions octoprint_tplinksmartplug/templates/tplinksmartplug_navbar.jinja2
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
<!-- ko if: settings.settings.plugins.tplinksmartplug.useDropDown -->
<a href="javascript:void(0)" title="TPLink SmartPlugs" class="dropdown-toggle" data-toggle="dropdown">
<i class="fa fa-plug"></i>
<b class="caret"></b>
</a>
<ul class="dropdown-menu" data-bind="foreach: arrSmartplugs">
<li>
<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>
</li>
</ul>
<!-- /ko -->
<!-- ko if: !(settings.settings.plugins.tplinksmartplug.useDropDown()) -->
<!-- ko foreach: arrSmartplugs -->
<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>
<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>
<!-- /ko -->
<!-- /ko -->


<div id="TPLinkSmartPlugWarning" data-bind="with: selectedPlug" class="modal hide fade">
<div class="modal-header">
<a href="#" class="close" data-dismiss="modal" aria-hidden="true">&times;</a>
<h3>TP-Link Smartplug</h3>
</div>
<div class="modal-body">
<p>
<!--ko text: label()--><!--/ko--> is currently <!--ko text: currentState()--><!--/ko-->.
<!--ko text: label()--><!--/ko--> is currently <!--ko text: currentState()--><!--/ko-->.
</p>
<p>
{{ _('Are you sure you want to proceed?') }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,15 @@
</div>
</div>
</div>
<div class="row-fluid">
<div class="control-group">
<div class="controls">
<label class="checkbox">
<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') }}
</label>
</div>
</div>
</div>
</div>
</div>
<div class="row-fluid">
Expand Down
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 = "1.0.2"
plugin_version = "1.0.3"

# 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 c6c7854

Please sign in to comment.