Skip to content

Commit f9d8ca0

Browse files
Merge pull request #1645 from lsa-cs/add-tcpdu-upstream
driver/power: Add support for tinycontrol tcPDU
2 parents 728dd38 + 8bee780 commit f9d8ca0

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

doc/configuration.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,10 @@ Currently available are:
248248
It was tested on the *6G10A v2* model.
249249
`Manual <https://tinycontrol.pl/media/documents/manual_IP_Power_Socket__6G10A_v2_LANLIS-010-015_En-1.pdf>`__
250250

251+
``tinycontrol_tcpdu``
252+
Controls a Tinycontrol tcPDU via HTTP.
253+
See the `documentation <https://docs.tinycontrol.pl/en/tcpdu/api/commands/>`__
254+
251255
``poe_mib``
252256
Controls PoE switches using the PoE SNMP administration MiBs.
253257

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
""" A driver to control the Tinycontrol tcPDU
2+
Reference: https://docs.tinycontrol.pl/en/tcpdu/api/commands
3+
4+
Example configuration to use port #3 on a device with URL 'http://172.17.180.53/'
5+
6+
NetworkPowerPort:
7+
model: tinycontrol_tcpdu
8+
host: 'http://172.17.180.53'
9+
index: 3
10+
"""
11+
12+
from urllib.parse import urljoin
13+
14+
import requests
15+
16+
17+
def power_set(host, port, index, value):
18+
assert port is None
19+
20+
index = int(index)
21+
value = 1 if value else 0
22+
r = requests.get(urljoin(host, f"/api/v1/save/?out{index}={value}"))
23+
r.raise_for_status()
24+
25+
26+
def power_get(host, port, index):
27+
assert port is None
28+
29+
index = int(index)
30+
r = requests.get(urljoin(host, "/api/v1/read/status/?outValues"))
31+
r.raise_for_status()
32+
json_decoded = r.json()
33+
return json_decoded[f'out{index}'] == 1

tests/test_powerdriver.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ def test_import_backends(self):
290290
import labgrid.driver.power.eg_pms2_network
291291
import labgrid.driver.power.shelly_gen1
292292
import labgrid.driver.power.ubus
293+
import labgrid.driver.power.tinycontrol_tcpdu
293294

294295
def test_import_backend_eaton(self):
295296
pytest.importorskip("pysnmp")

0 commit comments

Comments
 (0)