|
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 | + |
| 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 |
0 commit comments