Skip to content

Commit

Permalink
0.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jneilliii committed Jan 14, 2018
1 parent bcf5e43 commit 1548f9c
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 16 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ This plugin is to control ITead Sonoff devices that have been flashed with [Sono

**Requires minimum Tasmota firmware version 5.11.0.**

**Single relay devices need to use 1 for index.**

[Changelog](changelog.md)

## Screenshots
Expand Down
12 changes: 12 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ 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.6.0] - 2018-01-14
### Fixed
- Single relay device issues

### Added
- single relay device option

### Notes
- single relay devices need to use 1 for index
- multiple relay devices need to disable the new option "Single Relay Device"

## [0.5.0] - 2018-01-11
### Notes
- previous settings will be erased during upgrade to accommodate for new features
Expand Down Expand Up @@ -40,6 +51,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Added
- Initial release.

[0.6.0]: https://github.com/jneilliii/OctoPrint-Tasmota/tree/0.6.0
[0.5.0]: https://github.com/jneilliii/OctoPrint-Tasmota/tree/0.5.0
[0.4.0]: https://github.com/jneilliii/OctoPrint-Tasmota/tree/0.4.0
[0.3.0]: https://github.com/jneilliii/OctoPrint-Tasmota/tree/0.3.0
Expand Down
45 changes: 31 additions & 14 deletions octoprint_tasmota/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import os
import re
import urllib2
import threading

class tasmotaPlugin(octoprint.plugin.SettingsPlugin,
octoprint.plugin.AssetPlugin,
Expand Down Expand Up @@ -41,8 +42,9 @@ def on_after_startup(self):

def get_settings_defaults(self):
return dict(
singleRelay = True,
debug_logging = False,
arrSmartplugs = [{'ip':'','displayWarning':True,'idx':'','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','username':'admin','password':'','icon':'icon-bolt','label':''}],
arrSmartplugs = [{'ip':'','displayWarning':True,'idx':'1','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','username':'admin','password':'','icon':'icon-bolt','label':''}],
)

def on_settings_save(self, data):
Expand Down Expand Up @@ -84,6 +86,8 @@ def get_template_configs(self):
##~~ SimpleApiPlugin mixin

def turn_on(self, plugip, plugidx, username="admin", password=""):
if self._settings.get(['singleRelay']):
plugidx = ''
self._tasmota_logger.debug("Turning on %s index %s." % (plugip, plugidx))
try:
webresponse = urllib2.urlopen("http://" + plugip + "/cm?user=" + username + "&password=" + password + "&cmnd=Power" + str(plugidx) + "%20on").read()
Expand All @@ -95,7 +99,8 @@ def turn_on(self, plugip, plugidx, username="admin", password=""):
chk = "UNKNOWN"

self._tasmota_logger.debug("Response: %s" % response)

if self._settings.get(['singleRelay']):
plugidx = '1'
if chk == "ON":
self._plugin_manager.send_plugin_message(self._identifier, dict(currentState="on",ip=plugip,idx=plugidx))
elif chk == "OFF":
Expand All @@ -105,6 +110,8 @@ def turn_on(self, plugip, plugidx, username="admin", password=""):
self._plugin_manager.send_plugin_message(self._identifier, dict(currentState="unknown",ip=plugip,idx=plugidx))

def turn_off(self, plugip, plugidx, username="admin", password=""):
if self._settings.get(['singleRelay']):
plugidx = ''
self._tasmota_logger.debug("Turning off %s index %s." % (plugip, plugidx))
try:
webresponse = urllib2.urlopen("http://" + plugip + "/cm?user=" + username + "&password=" + password + "&cmnd=Power" + str(plugidx) + "%20off").read()
Expand All @@ -116,7 +123,8 @@ def turn_off(self, plugip, plugidx, username="admin", password=""):
chk = "UNKNOWN"

self._tasmota_logger.debug("Response: %s" % response)

if self._settings.get(['singleRelay']):
plugidx = '1'
if chk == "ON":
self._plugin_manager.send_plugin_message(self._identifier, dict(currentState="on",ip=plugip,idx=plugidx))
elif chk == "OFF":
Expand All @@ -126,6 +134,8 @@ def turn_off(self, plugip, plugidx, username="admin", password=""):
self._plugin_manager.send_plugin_message(self._identifier, dict(currentState="unknown",ip=plugip,idx=plugidx))

def check_status(self, plugip, plugidx, username="admin", password=""):
if self._settings.get(['singleRelay']):
plugidx = ''
self._tasmota_logger.debug("Checking status of %s index %s." % (plugip, plugidx))
if plugip != "":
try:
Expand All @@ -139,7 +149,8 @@ def check_status(self, plugip, plugidx, username="admin", password=""):
chk = "UNKNOWN"

self._tasmota_logger.debug("%s index %s is %s" % (plugip, plugidx, chk))

if self._settings.get(['singleRelay']):
plugidx = '1'
if chk == "ON":
self._plugin_manager.send_plugin_message(self._identifier, dict(currentState="on",ip=plugip,idx=plugidx))
elif chk == "OFF":
Expand Down Expand Up @@ -189,17 +200,23 @@ def on_api_command(self, command, data):

def processGCODE(self, comm_instance, phase, cmd, cmd_type, gcode, *args, **kwargs):
if gcode:
if cmd.count(" ") >= 2:
if cmd.startswith("M8") and cmd.count(" ") >= 2:
plugip = cmd.split()[1]
plugidx = cmd.split()[2]
if cmd.startswith("M80"):
self._plugin_manager.send_plugin_message(self._identifier, dict(currentState="unknown",gcodeon=True,ip=plugip,idx=plugidx))
self._tasmota_logger.debug("Received M80 command, attempting power on of %s index %s." % (plugip,plugidx))
return
elif cmd.startswith("M81"):
self._plugin_manager.send_plugin_message(self._identifier, dict(currentState="unknown",gcodeoff=True,ip=plugip,idx=plugidx))
self._tasmota_logger.debug("Received M81 command, attempting power off of %s index %s." % (plugip,plugidx))
return
plugidx = cmd.split()[2]
for plug in self._settings.get(["arrSmartplugs"]):
if plug["ip"].upper() == plugip.upper() and plug["idx"] == plugidx and plug["gcodeEnabled"]:
if cmd.startswith("M80"):
t = threading.Timer(int(plug["gcodeOnDelay"]),self.turn_on, [plug["ip"],plug["idx"]],{'username': plug["username"],'password': plug["password"]})
t.start()
self._tasmota_logger.debug("Received M80 command, attempting power on of %s index %s." % (plugip,plugidx))
return
elif cmd.startswith("M81"):
t = threading.Timer(int(plug["gcodeOnDelay"]),self.turn_off, [plug["ip"],plug["idx"]],{'username': plug["username"],'password': plug["password"]})
t.start()
self._tasmota_logger.debug("Received M81 command, attempting power off of %s index %s." % (plugip,plugidx))
return
else:
return
return


Expand Down
2 changes: 1 addition & 1 deletion octoprint_tasmota/static/js/tasmota.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ $(function() {

self.addPlug = function() {
self.settings.settings.plugins.tasmota.arrSmartplugs.push({'ip':ko.observable(''),
'idx':ko.observable(''),
'idx':ko.observable('1'),
'displayWarning':ko.observable(true),
'warnPrinting':ko.observable(false),
'gcodeEnabled':ko.observable(false),
Expand Down
7 changes: 7 additions & 0 deletions octoprint_tasmota/templates/tasmota_settings.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,11 @@
</label>
</div>
</div>
<div class="control-group">
<div class="controls">
<label class="checkbox">
<input type="checkbox" data-bind="checked: settings.settings.plugins.tasmota.singleRelay"> Single Relay Device.
</label>
</div>
</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-Tasmota"

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

# 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 1548f9c

Please sign in to comment.