Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions doc/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,13 @@ Currently available are:
<https://github.com/labgrid-project/labgrid/blob/master/labgrid/driver/power/shelly_gen1.py>`__
for details.

``shelly_gen2``
Controls relays of *Shelly* devices using the
`Gen2+ API <https://shelly-api-docs.shelly.cloud/gen2/General/RPCProtocol/>`__.
See the `docstring in the module
<https://github.com/labgrid-project/labgrid/blob/master/labgrid/driver/power/shelly_gen2.py>`__
for details.

``siglent``
Controls *Siglent SPD3000X* series modules via the `vxi11 Python module
<https://pypi.org/project/python-vxi11/>`_.
Expand Down
30 changes: 30 additions & 0 deletions labgrid/driver/power/shelly_gen2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""Interface for controlling relays of Shelly devices using the Gen 2+ API

NetworkPowerPort:
model: shelly_gen2
host: 'http://192.168.0.42'
index: 0

Will do a POST request to http://192.168.0.42/rpc to get the current
relay state or change the state.

Also, see the official Gen 2+ Device API documentation:
https://shelly-api-docs.shelly.cloud/gen2/General/RPCProtocol
"""

import requests


def power_set(host: str, port: int, index: int = 0, value: bool = True):
assert not port
payload = {"id": 1, "method": "Switch.Set", "params": {"id": index, "on": value}}
r = requests.post(f"{host}/rpc", json=payload)
r.raise_for_status()


def power_get(host: str, port: int, index: int = 0):
assert not port
payload = {"id": 1, "method": "Switch.GetStatus", "params": {"id": index}}
r = requests.post(f"{host}/rpc", json=payload)
r.raise_for_status()
return r.json()["output"]
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ include = [
"labgrid/driver/httpvideodriver.py",
"labgrid/driver/manualswitchdriver.py",
"labgrid/driver/power/gude8031.py",
"labgrid/driver/power/shelly_gen2.py",
"labgrid/driver/rawnetworkinterfacedriver.py",
"labgrid/protocol/**/*.py",
"labgrid/remote/**/*.py",
Expand Down