#9 Relais ausschalten wenn Octoprint heruntergefahren wird
#7 Relais einschalten wenn Octoprint gestartet wurde
This commit is contained in:
parent
bb9795b6df
commit
9eca03c29c
@ -19,6 +19,9 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
|
|||||||
self.ip = None
|
self.ip = None
|
||||||
self.intervall = 1
|
self.intervall = 1
|
||||||
self.onOffButtonEnabled = False
|
self.onOffButtonEnabled = False
|
||||||
|
self.powerOnOnStart = False
|
||||||
|
self.powerOffOnShutdown = False
|
||||||
|
self.powerOffDelay = 0
|
||||||
|
|
||||||
self._timer = None
|
self._timer = None
|
||||||
|
|
||||||
@ -34,7 +37,17 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
|
|||||||
self._logger.debug("intervall: %s" % self.intervall)
|
self._logger.debug("intervall: %s" % self.intervall)
|
||||||
|
|
||||||
self.onOffButtonEnabled = self._settings.get_boolean(["onOffButtonEnabled"])
|
self.onOffButtonEnabled = self._settings.get_boolean(["onOffButtonEnabled"])
|
||||||
self._logger.info("onOffButtonEnabled: %s" % self.onOffButtonEnabled)
|
self._logger.debug("onOffButtonEnabled: %s" % self.onOffButtonEnabled)
|
||||||
|
|
||||||
|
self.powerOnOnStart = self._settings.get_boolean(["powerOnOnStart"])
|
||||||
|
self._logger.debug("powerOnOnStart: %s" % self.powerOnOnStart)
|
||||||
|
|
||||||
|
self.powerOffOnShutdown = self._settings.get_boolean(["powerOffOnShutdown"])
|
||||||
|
self._logger.debug("powerOffOnShutdown: %s" % self.powerOffOnShutdown)
|
||||||
|
|
||||||
|
self.powerOffDelay = self._settings.get_int(["powerOffDelay"])
|
||||||
|
self._logger.debug("powerOffDelay: %s" % self.powerOffDelay)
|
||||||
|
|
||||||
self._timer_start()
|
self._timer_start()
|
||||||
|
|
||||||
def get_assets(self):
|
def get_assets(self):
|
||||||
@ -82,6 +95,21 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
|
|||||||
except requests.exceptions.ConnectionError:
|
except requests.exceptions.ConnectionError:
|
||||||
self._logger.info("Error during set Relais state")
|
self._logger.info("Error during set Relais state")
|
||||||
|
|
||||||
|
# Sets the switch to a specific inverse newState,
|
||||||
|
# waits for a specified amount of time (max 3h),
|
||||||
|
# then sets the the switch to the newState.
|
||||||
|
def _powerCycleRelais(self, newState, time):
|
||||||
|
try:
|
||||||
|
value = '0'
|
||||||
|
if (newState == True):
|
||||||
|
value = '1'
|
||||||
|
request = requests.post(
|
||||||
|
'http://{}/relay'.format(self.ip), json={'mode': value, 'time': time}, timeout=1)
|
||||||
|
if not request.status_code == 200:
|
||||||
|
self._logger.info("Could not powerCycle Relais, Http Status Code: {}".format(request.status_code))
|
||||||
|
except requests.exceptions.ConnectionError:
|
||||||
|
self._logger.info("Error during powerCycle Relais")
|
||||||
|
|
||||||
def _toggleRelay(self):
|
def _toggleRelay(self):
|
||||||
try:
|
try:
|
||||||
request = requests.get(
|
request = requests.get(
|
||||||
@ -110,25 +138,37 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
|
|||||||
)
|
)
|
||||||
|
|
||||||
def on_after_startup(self):
|
def on_after_startup(self):
|
||||||
pass
|
if self.powerOnOnStart:
|
||||||
|
self._setRelaisState(True)
|
||||||
|
|
||||||
def on_shutdown(self):
|
def on_shutdown(self):
|
||||||
pass
|
if self.powerOffOnShutdown:
|
||||||
|
if self.powerOffDelay <= 0:
|
||||||
|
self._setRelaisState(False)
|
||||||
|
else:
|
||||||
|
self._powerCycleRelais(False, self.powerOffDelay)
|
||||||
|
|
||||||
def on_settings_migrate(self, target, current):
|
def on_settings_migrate(self, target, current):
|
||||||
if target > current:
|
if target > current:
|
||||||
if current <= 1:
|
if current <= 1:
|
||||||
self.onOffButtonEnabled = False
|
self.onOffButtonEnabled = False
|
||||||
pass
|
pass
|
||||||
|
if current <= 2:
|
||||||
|
self.powerOnOnStart = False,
|
||||||
|
self.powerOffOnShutdown = False,
|
||||||
|
self.powerOffDelay = 0
|
||||||
|
|
||||||
def get_settings_version(self):
|
def get_settings_version(self):
|
||||||
return 2
|
return 3
|
||||||
|
|
||||||
def get_settings_defaults(self):
|
def get_settings_defaults(self):
|
||||||
return dict(
|
return dict(
|
||||||
ip=None,
|
ip=None,
|
||||||
intervall=1,
|
intervall=1,
|
||||||
onOffButtonEnabled=False
|
onOffButtonEnabled=False,
|
||||||
|
owerOnOnStart=False,
|
||||||
|
powerOffOnShutdown=False,
|
||||||
|
powerOffDelay=0
|
||||||
)
|
)
|
||||||
|
|
||||||
def on_settings_save(self, data):
|
def on_settings_save(self, data):
|
||||||
|
@ -21,8 +21,31 @@
|
|||||||
<div class="control-group">
|
<div class="control-group">
|
||||||
<div class="controls">
|
<div class="controls">
|
||||||
<label class="checkbox">
|
<label class="checkbox">
|
||||||
<input type="checkbox" id="mystromswitchShowToggleButton" data-bind="checked: settings.plugins.mystromswitch.onOffButtonEnabled">Toggle Button Enabled
|
<input type="checkbox" data-bind="checked: settings.plugins.mystromswitch.onOffButtonEnabled">Toggle Button Enabled
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="control-group">
|
||||||
|
<div class="controls">
|
||||||
|
<label class="checkbox">
|
||||||
|
<input type="checkbox" data-bind="checked: settings.plugins.mystromswitch.powerOnOnStart">Turn relais ON on Octoprint start
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="control-group">
|
||||||
|
<div class="controls">
|
||||||
|
<label class="checkbox">
|
||||||
|
<input type="checkbox" data-bind="checked: settings.plugins.mystromswitch.powerOffOnShutdown">Turn relais OFF on Octoprint shutdown
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="control-group">
|
||||||
|
<label class="control-label">{{ _('Turn Relais Off Delay') }}</label>
|
||||||
|
<div class="controls">
|
||||||
|
<input type="number" class="input-block-level" data-bind="value: settings.plugins.mystromswitch.powerOffDelay">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
2
setup.py
2
setup.py
@ -14,7 +14,7 @@ plugin_package = "octoprint_mystromswitch"
|
|||||||
plugin_name = "OctoPrint-MyStromSwitch"
|
plugin_name = "OctoPrint-MyStromSwitch"
|
||||||
|
|
||||||
# The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module
|
# The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module
|
||||||
plugin_version = "0.2.0"
|
plugin_version = "0.3.0"
|
||||||
|
|
||||||
# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
|
# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
|
||||||
# module
|
# module
|
||||||
|
Loading…
Reference in New Issue
Block a user