Last active
August 29, 2015 14:26
-
-
Save milhauszn/d77e5ef99a89b9df14fe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function | |
import sys | |
import datetime | |
import time | |
from device import Device | |
def armed(balk): | |
if balk == "1": | |
device.send_command("TX ENROLL:0 PGX:0 PGY:0 ALARM:0 BEEP:FAST") | |
print ("otevreny balkon") | |
time.sleep(10) | |
else: | |
device.send_command("TX ENROLL:0 PGX:0 PGY:0 ALARM:0 BEEP:SLOW") | |
print ("zamykani") | |
time.sleep(3) | |
device.send_command("TX ENROLL:0 PGX:0 PGY:0 ALARM:0 BEEP:NONE") | |
print("zapnuto") | |
stav= reader.next() | |
while (stav[1:9] == "xxxxxxxx" and stav[22] == "0") == False: #druhou klicenku pridat | |
if ((stav[1:9] == "xxxxxxxx") or (stav[1:9] == "xxxxxxxx")) and stav[18] == "S": #doplnit magneticke otvirani treba na balkon | |
device.send_command("TX ENROLL:0 PGX:0 PGY:0 ALARM:1 BEEP:NONE") | |
time.sleep(1) | |
print("narusitel") | |
device.send_command("TX ENROLL:0 PGX:1 PGY:0 ALARM:1 BEEP:NONE") | |
time.sleep(1) | |
while (stav[1:9] == "xxxxxxxx" and stav[22] == "0") == False: #pridat vypnuti casem za 5min a druhou klicenku | |
print("neni stav klicenky na vypnuti") | |
stav= reader.next() | |
print("vypnuto klicenkou") | |
device.send_command("TX ENROLL:0 PGX:1 PGY:0 ALARM:0 BEEP:NONE") | |
if stav[1:9] == "xxxxxxxx" and stav[19] == "S" : #otres odemykani dveri, zatim upozorni potichu | |
device.send_command("TX ENROLL:0 PGX:0 PGY:0 ALARM:0 BEEP:FAST") | |
time.sleep(2) | |
print("otres dvere") | |
stav= reader.next() | |
print("alarm vypnut") | |
if __name__ == "__main__": | |
device = Device(device="/dev/ttyUSB0") | |
reader = device.gen_lines() | |
balkon = "0" | |
tma = False | |
zapnuto = False | |
cas= datetime.datetime.now() | |
zapad =cas.replace(hour=20, minute=30, second=00, microsecond=0) #treba pulhodka pred zapadem | |
pulnoc = cas.replace(hour=23, minute=30, second=00, microsecond=0) | |
pohyb_cas= datetime.datetime.now() | |
while True: | |
line = reader.next() | |
if line[1:9] == "xxxxxxxx" and len(line)> 32: #cteni magnetu, delka kvuli beacon vysilani | |
balkon = line[34] | |
if balkon == "0" and tma: | |
device.send_command("TX ENROLL:0 PGX:1 PGY:0 ALARM:0 BEEP:NONE") | |
else: | |
device.send_command("TX ENROLL:0 PGX:0 PGY:0 ALARM:0 BEEP:NONE") | |
if line[1:9] == "xxxxxxxx" and line[22]=="1": #pridat druhou klicenku | |
armed(balkon) | |
device.send_command("TX ENROLL:0 PGX:0 PGY:0 ALARM:0 BEEP:NONE") | |
print("konec armed") | |
if line[1:9] == "xxxxxxxx" and line[18] == "S": | |
phyb = True | |
pohyb_cas= datetime.datetime.now() | |
cas= datetime.datetime.now() | |
if cas > zapad and cas< pulnoc: | |
tma = True | |
else: | |
tma = False | |
if tma and balkon =="0" and zapnuto == False: | |
device.send_command("TX ENROLL:0 PGX:1 PGY:0 ALARM:0 BEEP:NONE") | |
zapnuto = True | |
elif tma== False and zapnuto: | |
device.send_command("TX ENROLL:0 PGX:0 PGY:0 ALARM:0 BEEP:NONE") | |
zapnuto = False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment