-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebPower.py
More file actions
53 lines (45 loc) · 1.97 KB
/
Copy pathWebPower.py
File metadata and controls
53 lines (45 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import subprocess, os
import Logger
class WebPower:
def __init__(self, logger: Logger.Logger, index: int):
self.logger = logger
self.index=index
def PowerOn(self):
home = os.environ["HOME"]
if not os.path.exists("%s/stepper/lnrelay-eth.sh"%(home)):
print("Failed to find the webpower script for toggling power!")
return
retval=subprocess.check_output(["%s/stepper/lnrelay-eth.sh"%(home),str(self.index),"ON"]).decode()
if (int(retval) != 0):
print("Warning! Error in %s/stepper/lnrelay-eth.sh"%(home))
return False
return True
def PowerOff(self):
home = os.environ["HOME"]
if not os.path.exists("%s/stepper/lnrelay-eth.sh"%(home)):
print("Failed to find the webpower script for toggling power!")
return
retval=subprocess.check_output(["%s/stepper/lnrelay-eth.sh"%(home),str(self.index),"OFF"]).decode()
if (int(retval) != 0):
print("Warning! Error in %s/stepper/lnrelay-eth.sh"%(home))
return False
return True
def CheckStatus(self):
home = os.environ["HOME"]
if not os.path.exists("%s/stepper/lnrelay-check.sh"%(home)):
print("Failed to find the webpower script for checking status!")
return
retval=subprocess.check_output(["%s/stepper/lnrelay-check.sh"%(home),str(self.index)]).decode()
retval=retval.split("\n")
if (int(retval[1]) != 0):
print("Warning! Error in %s/stepper/lnrelay-check.sh"%(home))
if (retval[0] == "ON"):
return True
elif (retval[0] == "OFF"):
return False
else:
print("Warning! %s/stepper/lnrelay-check.sh gave unexpected output"%(home))
return False
def PrintStatus(self):
home = os.environ["HOME"]
print(f"Webpower switch is {'enabled' if self.CheckStatus() else 'disabled'}!")