Add getter for relay state

Signed-off-by: Thomas Klaehn <tkl@blackfinn.de>
This commit is contained in:
Thomas Klaehn 2022-05-23 11:53:50 +02:00
parent 3204bf9a3f
commit d0a8384cee

View File

@ -25,6 +25,12 @@ def switch_relay(relay: int, state: bool):
log.info("switching relay %s (pin %s) %s", relay, pin, state)
GPIO.output(pin, not state)
def get_relay_state(relay: int) -> bool:
pin = int(GPIOS[relay - 1])
state = GPIO.input(pin)
log = logging.getLogger()
log.info("Relay state of relay %s (pin %s) %s", relay, pin, state)
return state
def init_relays():
"""Init relays"""
@ -47,6 +53,7 @@ def main():
server = SimpleXMLRPCServer((HOST, PORT), allow_none=True)
server.register_function(switch_relay, 'switch_relay')
server.register_function(get_relay_state, 'get_relay_state')
log.info('Control-c to quit')
server.serve_forever()