Skip to content

Commit 918e459

Browse files
BenM-githubmoqmar
andcommitted
driver/power/gude: Make gude.py generic for all Gude PDUs
- changed the assert upper limit to a dynamic value. - changed api endpoint to status.json, as it should be supported for all Gude PDUs Co-authored-by: Moritz Marquardt <[email protected]>
1 parent fc8901c commit 918e459

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

labgrid/driver/power/gude8031.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import requests
22

33
# Driver has been tested with:
4-
# * Gude Expert Power Control 8031()
4+
# * Gude Expert Power Control 8031-1
55
# * Gude Expert Power Control 87-1210-18
6-
# This device needs to be used in 'Basic Compatible' mode for HTTP GET
7-
# to be usable. Do not turn on session authentication.
8-
6+
#
7+
# This device needs to be used in 'Basic Compatible' mode for HTTP GET
8+
# to be usable. Do not turn on session authentication.
9+
#
910
# HTTP-GET API is defined in the Gude EPC-HTTP-Interface specification:
1011
# http://wiki.gude.info/EPC_HTTP_Interface
1112
#
@@ -20,7 +21,8 @@
2021

2122
def power_set(host, port, index, value):
2223
index = int(index)
23-
assert 1 <= index <= 20
24+
upper_limit = count_ports(host, port)
25+
assert 1 <= index <= upper_limit, f'index ({index}) out of port range (1-{upper_limit})'
2426
# access the web interface...
2527
value = 1 if value else 0
2628
r = requests.get(f"http://{host}:{port}/status.json?components=0&cmd=1&p={index}&s={value}")
@@ -29,12 +31,19 @@ def power_set(host, port, index, value):
2931

3032
def power_get(host, port, index):
3133
index = int(index)
32-
assert 1 <= index <= 20
3334

3435
# get the component status
3536
r = requests.get(f"http://{host}:{port}/status.json?components=1")
3637
r.raise_for_status()
3738

38-
state = r.json()["outputs"][index - 1]["state"]
39+
body = r.json()
40+
assert 1 <= index <= len(body["outputs"]), f'index ({index}) out of port range (1-{len(body["outputs"])})'
41+
state = body["outputs"][index - 1]["state"]
3942

4043
return state
44+
45+
46+
def count_ports(host, port):
47+
r = requests.get(f"http://{host}:{port}/status.json?components=1")
48+
r.raise_for_status()
49+
return len(r.json()["outputs"])

0 commit comments

Comments
 (0)