|
1 | | -import requests |
2 | | - |
3 | | -# Driver has been tested with: |
4 | | -# Gude Expert Power Control 8031() |
5 | | - |
6 | | -# HTTP-GET API is defined in the Gude EPC-HTTP-Interface specification: |
7 | | -# http://wiki.gude.info/EPC_HTTP_Interface |
8 | | -# |
9 | | -# The `components=<N>` parameter defines which status information are |
10 | | -# included into the returned JSON. |
11 | | -# * `components=0` happily returns an empty response but still switches the |
12 | | -# outputs as requestd. |
13 | | -# * `components=1` only includes the output's state into the JSON. |
14 | | - |
15 | | -PORT = 80 |
16 | | - |
17 | | -def power_set(host, port, index, value): |
18 | | - index = int(index) |
19 | | - assert 1 <= index <= 8 |
20 | | - # access the web interface... |
21 | | - value = 1 if value else 0 |
22 | | - r = requests.get( |
23 | | - f"http://{host}:{port}/status.json?components=0&cmd=1&p={index}&s={value}" |
24 | | - ) |
25 | | - r.raise_for_status() |
26 | | - |
27 | | -def power_get(host, port, index): |
28 | | - index = int(index) |
29 | | - assert 1 <= index <= 8 |
30 | | - |
31 | | - # get the component status |
32 | | - r = requests.get(f"http://{host}:{port}/status.json?components=1") |
33 | | - r.raise_for_status() |
34 | | - |
35 | | - state = r.json()['outputs'][index - 1]['state'] |
36 | | - |
37 | | - return state |
| 1 | +import requests |
| 2 | + |
| 3 | +# Driver has been tested with: |
| 4 | +# * Gude Expert Power Control 8031() |
| 5 | +# * 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 | + |
| 9 | +# HTTP-GET API is defined in the Gude EPC-HTTP-Interface specification: |
| 10 | +# http://wiki.gude.info/EPC_HTTP_Interface |
| 11 | +# |
| 12 | +# The `components=<N>` parameter defines which status information are |
| 13 | +# included into the returned JSON. |
| 14 | +# * `components=0` happily returns an empty response but still switches the |
| 15 | +# outputs as requested. |
| 16 | +# * `components=1` only includes the output's state into the JSON. |
| 17 | + |
| 18 | +PORT = 80 |
| 19 | + |
| 20 | + |
| 21 | +def power_set(host, port, index, value): |
| 22 | + index = int(index) |
| 23 | + assert 1 <= index <= 20 |
| 24 | + # access the web interface... |
| 25 | + value = 1 if value else 0 |
| 26 | + r = requests.get(f"http://{host}:{port}/status.json?components=0&cmd=1&p={index}&s={value}") |
| 27 | + r.raise_for_status() |
| 28 | + |
| 29 | + |
| 30 | +def power_get(host, port, index): |
| 31 | + index = int(index) |
| 32 | + assert 1 <= index <= 20 |
| 33 | + |
| 34 | + # get the component status |
| 35 | + r = requests.get(f"http://{host}:{port}/status.json?components=1") |
| 36 | + r.raise_for_status() |
| 37 | + |
| 38 | + state = r.json()["outputs"][index - 1]["state"] |
| 39 | + |
| 40 | + return state |
0 commit comments