Source code for labgrid.driver.power.simplerest

""" Simple rest interface for Power Port. Used for ex. misc Raspberry Pi configs
    Author: Kjeld Flarup <>

    The URL given in hosts in exporter.yaml must replace {value} with '0' or '1'
    It is optional whether to use {index} or not.

      model: simplerest
      host: '{index}/{value}'
      index: 0

import requests

[docs] def power_set(host, port, index, value): assert port is None index = int(index) value = 1 if value else 0 r = requests.get(host.format(value=value, index=index)) r.raise_for_status()
[docs] def power_get(host, port, index): assert port is None index = int(index) # remove trailing / r = requests.get(host.format(value='', index=index).rstrip('/')) r.raise_for_status() return r.text == '1'