def toggle(relay_num, log=True, max_duration=None): pin = relays[relay_num] new_state = not bool(GPIO.input(pin)) GPIO.output(pin, new_state) cancel_timer(relay_num) if new_state == ON and max_duration is not None: timers[relay_num] = util.delay(off, max_duration, [relay_num], {"log_extra": "via timer"}) if log: log_action(relay_num, "toggle %s" % ('off' if new_state == OFF else 'on')) return new_state
def get_relay(relay_num): pin = relays[relay_num] return 'on' if GPIO.input(pin) == ON else 'off'
def get_sensor(sensor_num): return GPIO.input(sensors[sensor_num])