#8 Relais ein / ausschalten von Ocotprint aus

This commit is contained in:
David Zingg 2019-11-24 16:38:21 +01:00
parent 13e4540053
commit 81b5f2e5c3
3 changed files with 8 additions and 7 deletions

View File

@ -62,8 +62,9 @@ class MyStromSwitchPlugin(octoprint.plugin.SettingsPlugin,
try: try:
request = requests.get( request = requests.get(
'http://{}/report'.format(self.ip), timeout=1) 'http://{}/report'.format(self.ip), timeout=1)
self._plugin_manager.send_plugin_message(self._identifier, data = request.json()
request.json()) data["onOffButtonEnabled"] = self.onOffButtonEnabled
self._plugin_manager.send_plugin_message(self._identifier, data)
except (requests.exceptions.ConnectionError, ValueError): except (requests.exceptions.ConnectionError, ValueError):
self._logger.info('Connection Error Host: {}'.format(self.ip)) self._logger.info('Connection Error Host: {}'.format(self.ip))
else: else:

View File

@ -6,7 +6,7 @@ $(function() {
self.settings = parameters[1]; self.settings = parameters[1];
self.printer = parameters[2]; self.printer = parameters[2];
self.mystromswitchEnabled = ko.observable(); self.onOffButtonEnabled = ko.observable();
self.mystromswitchPowerValue = document.getElementById("mystromswitchPowerValue") self.mystromswitchPowerValue = document.getElementById("mystromswitchPowerValue")
self.onToggleRelayEvent = function(){ self.onToggleRelayEvent = function(){
@ -22,7 +22,7 @@ $(function() {
} }
self.onmystromswitchEvent = function() { self.onmystromswitchEvent = function() {
if (self.mystromswitchEnabled()) { if (self.onOffButtonEnabled()) {
$.ajax({ $.ajax({
url: API_BASEURL + "plugin/mystromswitch", url: API_BASEURL + "plugin/mystromswitch",
type: "POST", type: "POST",
@ -45,13 +45,13 @@ $(function() {
} }
} }
self.mystromswitchEnabled.subscribe(self.onmystromswitchEvent, self); self.onOffButtonEnabled.subscribe(self.onmystromswitchEvent, self);
self.onDataUpdaterPluginMessage = function(plugin, data) { self.onDataUpdaterPluginMessage = function(plugin, data) {
if (plugin != "mystromswitch" && plugin != "octoprint_mystromswitch") { if (plugin != "mystromswitch" && plugin != "octoprint_mystromswitch") {
return; return;
} }
self.mystromswitchEnabled(data.mystromswitchEnabled); self.onOffButtonEnabled(data.onOffButtonEnabled);
if(data.relay == false){ if(data.relay == false){
self.mystromswitchPowerValue.innerHTML = "Relay is off"; self.mystromswitchPowerValue.innerHTML = "Relay is off";
} else if (data.power != null) { } else if (data.power != null) {

View File

@ -1,4 +1,4 @@
<div class="sidebar_plugin_mystromswitch"> <div class="sidebar_plugin_mystromswitch">
<label class="control-label" id="mystromswitchPowerValue">Powerconsumption 0.0W</label> <label class="control-label" id="mystromswitchPowerValue">Powerconsumption 0.0W</label>
<button class="btn btn-primary" data-bind="click: onToggleRelayEvent, visible : settings.plugins.mystromswitch.onOffButtonEnabled">{{ _('Toggle Relais') }}</button> <button class="btn btn-primary" data-bind="click: onToggleRelayEvent, visible : onOffButtonEnabled">{{ _('Toggle Relais') }}</button>
</div> </div>