From 7153eecd57de94fdce4d8054af4f5e9661ea0cbb Mon Sep 17 00:00:00 2001 From: Thomas Schmid Date: Thu, 18 Oct 2018 21:56:13 +0200 Subject: [PATCH] add doorlock-slave --- doorlockd-slave | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 doorlockd-slave diff --git a/doorlockd-slave b/doorlockd-slave new file mode 100755 index 0000000..2dc75ff --- /dev/null +++ b/doorlockd-slave @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 + +""" +Doorlockd -- Binary Kitchen's smart door opener + +Copyright (c) Binary Kitchen e.V., 2018 + +Author: + Thomas Schmid + +This work is licensed under the terms of the GNU GPL, version 2. See +the LICENSE file in the top-level directory. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +details. +""" + +from pydoorlock.EventClient import EventClient +from pydoorlock.Door import DoorState +import json + +state = DoorState(0) + +if __name__ == "__main__": + #we need a thread that listens for server sent events + #we need a thread that does serial port communication + #do the networking in the main thread + + ec = EventClient("http://localhost:8080/push") + for event in ec.events(): + data = json.loads(event['data']) + state = DoorState(data['status']) + print(state)