File tree Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change
1
+ import requests
2
+ import re
3
+
4
+ from labgrid .driver .exception import ExecutionError
5
+
6
+
7
+ # This driver implements a power port for Aviosys Power Switches.
8
+ # Aviosys HTTP web-interface is described here https://www.aviosys.com/products/lib/httpapi.html
9
+ # The command format is http://ip:port/set.cmd?user=account+pass=password+cmd=command
10
+
11
+ # The powerdriver.py uses the 'PORT' variable => backend_port = getattr(self.backend, 'PORT', None)
12
+ PORT = 80
13
+ USER = "admin"
14
+ PASS = 12345678
15
+ NUMBER_OF_OUTLETS = 4
16
+
17
+ def power_set (host , port , index , value ):
18
+ # <!--CGI-DATABEG-->
19
+ # <p>
20
+ # p61=1</p>
21
+ # <!--CGI-DATAEND-->
22
+ index = int (index )
23
+ assert 1 <= index <= NUMBER_OF_OUTLETS
24
+ value = 1 if value else 0
25
+
26
+ r = requests .get (
27
+ f"http://{ host } :{ port } /set.cmd?user={ USER } +pass={ PASS } +cmd=setpower+p6{ index } ={ value } "
28
+ )
29
+ r .raise_for_status ()
30
+
31
+ def power_get (host , port , index ):
32
+ # <!--CGI-DATABEG-->
33
+ # <p>
34
+ # p61=1,p62=0,p63=0,p64=0
35
+ # </p>
36
+ # <!--CGI-DATAEND-->
37
+ index = int (index )
38
+ assert 1 <= index <= NUMBER_OF_OUTLETS
39
+
40
+ r = requests .get (
41
+ f"http://{ host } :{ port } /set.cmd?user={ USER } +pass={ PASS } +cmd=getpower+p6{ index } =0"
42
+ )
43
+ r .raise_for_status ()
44
+
45
+ data = r .text
46
+ matches = re .findall (r'p6(\d)=(\d)' , data )
47
+ values = {f"p6{ index } " : int (value ) for index , value in matches }
48
+
49
+ state = values [f"p6{ index } " ]
50
+ return bool (int (state ))
You can’t perform that action at this time.
0 commit comments