Skip to content

Commit

Permalink
Add togglePSU API Command (#33)
Browse files Browse the repository at this point in the history
Add getPSUState API Command (#34)
  • Loading branch information
kantlivelong committed May 24, 2017
1 parent e91e5f2 commit 0727c63
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions octoprint_psucontrol/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import time
import threading
import os
from flask import make_response
from flask import make_response, jsonify

class PSUControl(octoprint.plugin.StartupPlugin,
octoprint.plugin.TemplatePlugin,
Expand Down Expand Up @@ -366,7 +366,9 @@ def turn_psu_off(self):
def get_api_commands(self):
return dict(
turnPSUOn=[],
turnPSUOff=[]
turnPSUOff=[],
togglePSU=[],
getPSUState=[]
)

def on_api_command(self, command, data):
Expand All @@ -377,6 +379,13 @@ def on_api_command(self, command, data):
self.turn_psu_on()
elif command == 'turnPSUOff':
self.turn_psu_off()
elif command == 'togglePSU':
if self.isPSUOn:
self.turn_psu_off()
else:
self.turn_psu_on()
elif command == 'getPSUState':
return jsonify(isPSUOn=self.isPSUon)

def get_settings_defaults(self):
return dict(
Expand Down

0 comments on commit 0727c63

Please sign in to comment.