def __init__(self): if (SettingsService != None): raise Exception('Triing to instanciate singleton') self._Settings = self._DefalutSettings self._Log = EventLog.getLoginServise() # try load setting from file try: file = open(self._SettingsPath, "r") self._Settings = json.load(file) print('Settings Loaded', self._Settings) file.close() self._Log.emit('SETTINGS_LOADED', EventLog.EventType.LOG) except FileNotFoundError: print('File not found') self._Log.emit('CANNOT_READ_SETTINGS', EventLog.EventType.SYSTEM_WARN, pld='File Not Found') self.saveUsedSettings() except Exception: print('File parse err') self._Log.emit('CANNOT_READ_SETTINGS', EventLog.EventType.SYSTEM_WARN, pld='Unknown Err') self.saveUsedSettings()
def __init__(self): self.SystemState = self.DefaultState self._Loger = EventLog.getLoginServise() def systemStateUpdateFactory(updatedString): def systemStateUpdateFactoryFunc(value): self.SystemState[updatedString] = value.Pld self.emitUpdateEvent() return systemStateUpdateFactoryFunc def lightUpdate(lightInfo): if (not hasattr(lightInfo, 'name') or lightInfo.name not in self.SystemState['Lights'] or not hasattr(lightInfo, 'state')): self._Loger.emit('Wrong Light Format', EventLog.EventType.SYSTEM_WARN) return self.SystemState['Lights'][lightInfo.name] = { 'status': lightInfo.status.value } self.emitUpdateEvent() def updateGate(state): self.SystemState['Gate'] = { 'status': state, 'lastOpened': datetime.datetime.now().isoformat() } self.emitUpdateEvent() def logIn(): self.SystemState['IsAuth'] = True self.SystemState['LastSuccesfullAuth'] = datetime.datetime.now( ).isoformat() self.emitUpdateEvent() def logOut(): self.SystemState['IsAuth'] = False self.emitUpdateEvent() def logInFaill(): self.SystemState['LastFailedAuth'] = datetime.datetime.now( ).isoformat() self.emitUpdateEvent() self._Loger.subscribeByName('Gate State Change', updateGate) self._Loger.subscribeByName('Temp', systemStateUpdateFactory('TempSensor')) self._Loger.subscribeByName('Light', systemStateUpdateFactory('LightSensor')) self._Loger.subscribeByName('Pres', systemStateUpdateFactory('PresSensor')) self._Loger.subscribeByName('Light state change', lightUpdate) self._Loger.subscribeByName('Auth Suspended', logOut) self._Loger.subscribeByName('Auth Succes', logIn) self._Loger.subscribeByName('Auth Failed', logInFaill)
def __init__(self): if (GateService != None): raise Exception('Trying to instantiate singleton!') self._Log = EventLog.getLoginServise() self._isOpen = False self._Servo = DevEvent.Sevro(12) self._close() # for IR_TRANSISTOR self._inputs = getUserInputsService()
def cleanup(): #global _IsCleanded #if _IsCleanded: # return #_IsCleanded = True eventLoger = EventLog.getLoginServise() print("INFO: cleaning ...") eventLoger.emit('CLEANING', EventLog.EventType.SYSTEM_LOG) IO.cleanup() print("END")
def wait_for_interrupts(): eventLoger = EventLog.getLoginServise() try: # infinite sleep on main thread while True: time.sleep(3600) except KeyboardInterrupt as e: print("PROGRAM EXIT, CTRL-C:\n{}".format(e)) eventLoger.emit('PROGRAM EXIT', EventLog.EventType.SYSTEM_LOG) sys.stdout.flush() except Exception as e: print("ERROR OCCURRED:\n{}".format(e)) eventLoger.emit('PROGRAM EXIT', EventLog.EventType.SYSTEM_ERR) sys.stdout.flush() """ finally:
def __init__(self): if (LightService != None): raise Exception('Trying to instantiate singleton!') self._Log = EventLog.getLoginServise() self._Led = { Common.LightsIds.IN_HOUSE.value: [DevEvent.LED(17), None, Common.LedState.OFF], Common.LightsIds.OUT_HOUSE.value: [DevEvent.LED(6), None, Common.LedState.OFF], Common.LightsIds.AUTH_SUCCES_LED.value: [DevEvent.LEDZeroLogic(23), None, Common.LedState.OFF], Common.LightsIds.ALARM_LED.value: [DevEvent.LEDZeroLogic(18), None, Common.LedState.OFF], Common.LightsIds.ALARM_BUZZER.value: [DevEvent.LED(19), None, Common.LedState.OFF] }
def __init__(self): if (UserInputsService != None): raise Exception('Trying to instantiate singleton!') """ self._LightsButton = DevEvent.Button(22) self._GateButton = DevEvent.Button(27) self._PirSensor = DevEvent.Button(5) self._IR_Transistor = DevEvent.Button(24) """ self._Log = EventLog.getLoginServise() self._ButtonLikeInput = { Common.InputIds.LIGTHS_BUTTON.value: DevEvent.Button(22), Common.InputIds.GATE_BUTTON.value: DevEvent.Button(27), Common.InputIds.PIR_SENSOR.value: DevEvent.Button(5), Common.InputIds.IR_TRANSISTOR.value: DevEvent.Button(24) }
def __init__(self): if (AuthService != None): raise Exception('Trying to instantiate singleton!') self._IsAuhtVar = False self._Log = EventLog.getLoginServise() self._RfId = DevEvent.RfId(25) self._Settings = SettingsService.getSettingsService() settings = SettingsService.getSettingsService() def idLoaded(uid): if settings.matchRfid(uid): self._authSucces() else: self._authFail() self._RfId.subscribe(idLoaded)
def generateRandomString(): letters = string.ascii_lowercase return ''.join(random.choice(letters) for i in range(10)) RspAccesToken = '' if 'RSP_ACCES_TOKEN' in os.environ: RspAccesToken = os.environ['RSP_ACCES_TOKEN'] app = Flask(__name__) # JWT KEY app.config['SECRET_KEY'] = generateRandomString() # app.config['SECRET_KEY'] = 'SECRET' CORS(app) loger = EventLog.getLoginServise() lights = DevServices.getLightService() gate = DevServices.getGateService() def init(): Main.init() eventList = [] # Test route @app.route('/api') def hello_world(): return 'Api root'
def __init__(self): self._Log = EventLog.getLoginServise() self._Camera = None if Camera.isCameraReady(): self._Camera = Camera.Camera("assets/OpenCv/encode.picle")