Source code for labgrid.driver.power.shelly_gen1

"""Interface for controlling relays of Shelly devices using the Gen 1 API

      model: shelly_gen1
      host: ''
      index: 0

  Will do a GET request to to get the current
  relay state, and a POST request to with request
  data of 'turn=off' or 'turn=on' to change the relay state.

  Also, see the official Gen 1 Device API documentation:

import json

import requests

[docs] def power_set(host:str, port:int, index:int=0, value:bool=True): assert not port turn = "on" if value else "off" r ="{host}/relay/{index}", data={'turn': turn}) r.raise_for_status()
[docs] def power_get(host:str, port:int, index:int): assert not port r = requests.get(f"{host}/relay/{index}") r.raise_for_status() return json.loads(r.text)['ison']