def do_control(self, control_order, para): result_object = dict(success=False, message='unknown error') logger.debug(json.dumps(para, sort_keys=True, indent=4)) try: for parameter_name in para.keys(): try: para[parameter_name] = unquote_plus( para[parameter_name][0]) except KeyError: para[parameter_name] = '' except IndexError: para[parameter_name] = '' if control_order == "trigger_event": result_object['message'] = doorpi.DoorPi( ).event_handler.fire_event_synchron(**para) if result_object['message'] is True: result_object['success'] = True result_object['message'] = "fire Event was success" else: result_object['success'] = False elif control_order == "config_value_get": # section, key, default, store result_object['success'] = True result_object['message'] = control_config_get_value(**para) elif control_order == "config_value_set": # section, key, value, password result_object['success'] = control_config_set_value(**para) result_object['message'] = "config_value_set %s" % ( 'success' if result_object['success'] else 'failed') elif control_order == "config_value_delete": # section and key result_object['success'] = control_config_delete_key(**para) result_object['message'] = "config_value_delete %s" % ( 'success' if result_object['success'] else 'failed') elif control_order == "config_save": # configfile result_object['success'] = control_config_save(**para) result_object['message'] = "config_save %s" % ( 'success' if result_object['success'] else 'failed') elif control_order == "config_get_configfile": result_object['message'] = control_config_get_configfile() result_object['success'] = True if result_object[ 'message'] != "" else False except Exception as exp: result_object['message'] = str(exp) return result_object
def write_statusfile(filename, filecontent): try: filename = doorpi.DoorPi().parse_string(filename) filecontent = doorpi.DoorPi().parse_string(filecontent) try: doorpi_status = DoorPiStatus(doorpi.DoorPi()) doorpi_status_json_beautified = doorpi_status.json_beautified doorpi_status_json = doorpi_status.json filecontent = filecontent.replace( '!DOORPI_STATUS.json_beautified!', doorpi_status_json_beautified) filecontent = filecontent.replace('!DOORPI_STATUS.json!', doorpi_status_json) except: logger.exception("error while creating status") except: logger.warning( "while action statusfile - error to get DoorPi().parse_string") return False try: file = open(filename, 'w') try: file.write(filecontent) file.flush() finally: file.close() except IOError as e: logger.warning("while action statusfile - I/O error(%s): %s" % (e.errno, e.strerror)) return False return True
def __init__(self, input_pins, output_pins, keyboard_name, conf_pre, conf_post, *args, **kwargs): self.keyboard_name = keyboard_name self._InputPins = map(int, input_pins) self._OutputPins = map(int, output_pins) self.last_key = "" self.last_key_time = 0 self.__active = False self.__timeout = 0 ## Spezielle Handler für (Un-)bekannte Finger registrieren doorpi.DoorPi().event_handler.register_event('OnFingerprintFoundUnknown', __name__) doorpi.DoorPi().event_handler.register_event('OnFingerprintFoundKnown', __name__) ## Config-Einträge lesen, falls dort vorhanden. section_name = conf_pre + 'keyboard' + conf_post self.__port = doorpi.DoorPi().config.get(section_name, 'port', "/dev/ttyAMA0") self.__baudrate = doorpi.DoorPi().config.get_int(section_name, 'baudrate', 57600) self.__sensoraddr = doorpi.DoorPi().config.get(section_name, 'address', 0xFFFFFFFF) self.__password = doorpi.DoorPi().config.get(section_name, 'password', 0x00000000) self.__security = doorpi.DoorPi().config.get_int(section_name, 'security', 70) self.__ontime = doorpi.DoorPi().config.get_int(section_name, 'ontime', False) ## Sensor initialisieren try: self.__sensor = PyFingerprint(self.__port, self.__baudrate, self.__sensoraddr, self.__password) if (self.__sensor.verifyPassword() == False): logger.warning('The given fingerprint sensor password is wrong!') logger.debug('Currently used templates: ' + str(self.__sensor.getTemplateCount()) + '/' + str(self.__sensor.getStorageCapacity())) ## Events für hinterlegte InputPins registrieren (damit diese auch ausgelöst werden) for input_pin in self._InputPins: self._register_EVENTS_for_pin(input_pin, __name__) ## Dauerbetrieb oder nur auf Kommando? (ontime ist null) if self.__ontime < 1: self.__active = True logger.debug('ontime =0 ! Running permanently') ## Thread für den eigtl Lesevorgang starten self._shutdown = False self._thread = threading.Thread(target = self.readFingerprint) self._thread.daemon = True self._thread.start() self.register_destroy_action() except Exception as ex: logger.exception(ex)
def get(parameters): conf = doorpi.DoorPi().config snapshot_size = conf.get_string(DOORPI_SECTION, 'snapshot_size', '1280x720') snapshot_path = conf.get_string_parsed( DOORPI_SECTION, 'snapshot_path', '!BASEPATH!/../DoorPiWeb/snapshots/') number_of_snapshots = conf.get_int(DOORPI_SECTION, 'number_of_snapshots', 10) if len(conf.get(SIPPHONE_SECTION, 'capture_device', '')) > 0: return SnapShotAction(take_snapshot, size=snapshot_size, path=snapshot_path, max=number_of_snapshots) logger.warning('can not create snapshot - video disabled')
def set_output(self, pin, value, log_output=True): parsed_pin = doorpi.DoorPi().parse_string('!' + str(pin) + '!') if parsed_pin != ('!' + str(pin) + '!'): pin = parsed_pin if pin not in self._OutputPins: return False value = str(value).lower() in HIGH_LEVEL log_output = str(log_output).lower() in HIGH_LEVEL written_value = self.__write_file(os.path.join(self.__base_path_output, pin), value) if log_output: logger.debug('out(pin = %s, value = %s, log_output = %s)', pin, written_value, log_output) self._OutputStatus[pin] = value return True
def get(parameters): parameter_list = parameters.split(',') if len(parameter_list) > 3: return fallback_out_triggered(parameters) pin = parameter_list[0] value = parameter_list[1] if len(parameter_list) is 2: log_output = True else: log_output = parameter_list[2] return OutAction(doorpi.DoorPi().keyboard.set_output, pin=pin, value=value, log_output=log_output)
def createSnapshot(): snapshot_file = '/tmp/doorpi.jpg' size = doorpi.DoorPi().config.get_string('DoorPi', 'snapshot_size', '1280x720') command = "fswebcam --no-banner -r " + size + " " + snapshot_file try: retcode = subprocess.call(command, shell=True) if retcode != 0: logger.error('error creating snapshot') else: logger.info('snapshot created: %s', snapshot_file) return snapshot_file except OSError as e: logger.error('error creating snapshot') return ''
def set_output(self, pin, value, log_output=True): parsed_pin = doorpi.DoorPi().parse_string("!" + str(pin) + "!") if parsed_pin != "!" + str(pin) + "!": pin = parsed_pin value = str(value).lower() in HIGH_LEVEL if self._polarity is 1: value = not value log_output = str(log_output).lower() in HIGH_LEVEL if pin not in self._OutputPins: return False if log_output: logger.debug("out(pin = %s, value = %s, log_output = %s)", pin, value, log_output) self._OutputStatus[pin] = value return True
def get(parameters): parameter_list = parameters.split(',') # more than 3 parameters? 4. parameter should be timeout if len(parameter_list) > 3: return fallback_out_triggered(parameters) pin = parameter_list[0] value = parameter_list[1] # logging specified in action call? if len(parameter_list) is 2: log_output = True else: log_output = parameter_list[2] return OutAction(doorpi.DoorPi().keyboard.set_output, pin=pin, value=value, log_output=log_output)
def prepare(): doorpi.DoorPi().event_handler.register_event('OnWebServerRequest', __name__) doorpi.DoorPi().event_handler.register_event('OnWebServerRequestGet', __name__) doorpi.DoorPi().event_handler.register_event('OnWebServerRequestPost', __name__) doorpi.DoorPi().event_handler.register_event( 'OnWebServerVirtualResource', __name__) doorpi.DoorPi().event_handler.register_event('OnWebServerRealResource', __name__) # for do_control doorpi.DoorPi().event_handler.register_event('OnFireEvent', __name__) doorpi.DoorPi().event_handler.register_event('OnConfigKeySet', __name__) doorpi.DoorPi().event_handler.register_event('OnConfigKeyDelete', __name__)
def __init__(self, input_pins, output_pins, conf_pre, conf_post, keyboard_name, *args, **kwargs): logger.debug("FileSystem.__init__(input_pins = %s, output_pins = %s)", input_pins, output_pins) self.keyboard_name = keyboard_name self._InputPins = map(str, input_pins) self._OutputPins = map(str, output_pins) self._last_received_chars = "" self.last_key = "" for input_pin in self._InputPins: self._register_EVENTS_for_pin(input_pin, __name__) # use set_output to register status @ dict self.__OutputStatus for output_pin in self._OutputPins: self.set_output(output_pin, 0, False) # somit wirds aus der Config-Datei geladen, falls dort vorhanden. section_name = conf_pre+'keyboard'+conf_post port = CONFIG.get(section_name, 'port', "/dev/ttyUSB0") baudrate = CONFIG.get_int(section_name, 'baudrate', 9600) self._input_stop_flag = CONFIG.get(section_name, 'input_stop_flag', OS_LINESEP) self._input_max_size = CONFIG.get_int(section_name, 'input_max_size', 255) self._output_stop_flag = CONFIG.get(section_name, 'output_stop_flag', OS_LINESEP) self._ser = serial.Serial(port, baudrate) self._ser.timeout = 1 #block read, 0 for #non-block read, > 0 for timeout block read self._ser.close() #self._ser.bytesize = serial.EIGHTBITS #number of bits per bytes #self._ser.parity = serial.PARITY_NONE #set parity check: no parity #self._ser.stopbits = serial.STOPBITS_ONE #number of stop bits #self._ser.xonxoff = False #disable software flow control #self._ser.rtscts = False #disable hardware (RTS/CTS) flow control #self._ser.dsrdtr = False #disable hardware (DSR/DTR) flow control #self._ser.writeTimeout = 0 #timeout for write self._ser.open() self._shutdown = False self._thread = threading.Thread(target = self.read_usb_plain) self._thread.daemon = True self._thread.start() doorpi.DoorPi().event_handler.register_action('OnShutdown', self.destroy)
def destroy(self): if self.is_destroyed: return logger.debug('destroy') # shutdown listener self.__listener.deactivate() # shutdown all output-pins for output_pin in self._OutputPins: self.set_output(output_pin, 0, False) # shutdown piface p.deinit() # unregister all event handler doorpi.DoorPi().event_handler.unregister_source(__name__, True) self.__destroyed = True
def ips_rpc_call_phonenumber_from_variable(key): try: if ips_rpc_check_variable_exists(key) is not True: raise Exception("var %s doesn't exist", key) type = ips_rpc_get_variable_type(key) if type is None: raise Exception("type of var %s couldn't find", key) # http://www.ip-symcon.de/service/dokumentation/befehlsreferenz/variablenverwaltung/ips-getvariable/ # Variablentyp (0: Boolean, 1: Integer, 2: Float, 3: String) elif type is not 3: raise Exception("phonenumber from var %s is not a string", key) phonenumber = ips_rpc_get_variable_value(key) logger.debug("fire now sipphone.call for this number: %s", phonenumber) doorpi.DoorPi().sipphone.call(phonenumber) logger.debug("finished sipphone.call for this number: %s", phonenumber) except Exception as ex: logger.exception("couldn't get phonenumber from IpsRpc (%s)", ex) return False return True
def pn532_recognized(self, tag): try: logger.debug("tag: %s", tag) hmm = str(tag) ID = str(hmm.split('ID=')[-1:])[2:-2] logger.debug("ID: %s", ID) if ID in self._InputPins: logger.debug("ID gefunden: %s", ID) self.last_key = ID self._fire_OnKeyDown(self.last_key, __name__) self._fire_OnKeyPressed(self.last_key, __name__) self._fire_OnKeyUp(self.last_key, __name__) doorpi.DoorPi().event_handler('OnFoundKnownTag', __name__) logger.debug("last_key is %s", self.last_key) except Exception as ex: logger.exception(ex) finally: logger.debug("pn532_recognized thread ended")
def set_output(self, pin, value, log_output=True): parsed_pin = doorpi.DoorPi().parse_string('!' + str(pin) + '!') if parsed_pin != ('!' + str(pin) + '!'): pin = parsed_pin pin = int(pin) value = str(value).lower() in HIGH_LEVEL if self._polarity is 1: value = not value log_output = str(log_output).lower() in HIGH_LEVEL if pin not in self._OutputPins: return False if log_output: logger.debug('out(pin = %s, value = %s, log_output = %s)', pin, value, log_output) p.digital_write(pin, value) self._OutputStatus[pin] = value return True
def ips_rpc_call_phonenumber_from_variable(key, config=None): try: if config is None: config = ips_rpc_create_config() if ips_rpc_check_variable_exists(key, config) is not True: raise Exception('no variable %s', key) type = ips_rpc_get_variable_type(key, config) if type is None: raise Exception('type of variable %s unknown', key) # variable types (0: boolean, 1: integer, 2: float, 3: string) elif type is not 3: raise Exception("type of variable %s is not a string", key) phonenumber = ips_rpc_get_variable_value(key, config) logger.debug('fire now sipphone.call for this number: %s', phonenumber) doorpi.DoorPi().sipphone.call(phonenumber) logger.debug('finished sipphone.call for this number: %s', phonenumber) except Exception as ex: logger.exception('couldn\'t get phonenumber from IpsRpc (%s)', ex) return False return True
def __init__(self, input_pins, output_pins, keyboard_name, conf_pre, conf_post, *args, **kwargs): self.keyboard_name = keyboard_name self._InputPins = map(int, input_pins) self._OutputPins = map(int, output_pins) self.last_key = "" self.last_key_time = 0 self.__timeout = 0 # Spezielle Handler fuer (Un-)bekannte Finger registrieren doorpi.DoorPi().event_handler.register_event( 'OnFingerprintFoundUnknown', __name__) doorpi.DoorPi().event_handler.register_event('OnFingerprintFoundKnown', __name__) # Config-Eintraege lesen, falls dort vorhanden. section_name = conf_pre + 'keyboard' + conf_post self.__port = doorpi.DoorPi().config.get(section_name, 'port', '/dev/ttyAMA0') self.__baudrate = doorpi.DoorPi().config.get_int( section_name, 'baudrate', 57600) self.__sensoraddr = doorpi.DoorPi().config.get(section_name, 'address', 0xFFFFFFFF) self.__password = doorpi.DoorPi().config.get(section_name, 'password', 0x00000000) self.__security = doorpi.DoorPi().config.get_int( section_name, 'security', 70) # Events für hinterlegte InputPins registrieren (damit diese auch ausgeloest werden) for input_pin in self._InputPins: self._register_EVENTS_for_pin(input_pin, __name__) # Dauerbetrieb oder nur auf Kommando? (Trigger-Pin definiert?) self.__active = (len(self._OutputPins) == 0) self._shutdown = False if self.__active: logger.debug('No trigger pin defined! Running permanently') # Thread für den eigtl Lesevorgang starten self._thread = threading.Thread(target=self.readFingerprint) self._thread.daemon = True self._thread.start() self.register_destroy_action()
def __init__(self, input_pins, output_pins, keyboard_name, conf_pre, conf_post, *args, **kwargs): self.keyboard_name = keyboard_name self.last_key = "" self.last_key_time = 0 # auslesen aus ini: section_name = conf_pre + 'keyboard' + conf_post self._device = doorpi.DoorPi().config.get_string_parsed( section_name, 'device', 'tty:AMA0:pn532') self._InputPins = map(str.upper, input_pins) self._InputPairs = {} self.__clf = nfc.ContactlessFrontend(self._device) #init nfc-reader for input_pin in self._InputPins: self._register_EVENTS_for_pin(input_pin, __name__) logger.debug("__init__ (input_pin = %s)", input_pin) #doorpi.DoorPi().event_handler.register_event('OnFoundKnownTag', __name__) self._shutdown = False self._thread = threading.Thread(target=self.pn532_read) self._thread.daemon = True self._thread.start() self.register_destroy_action()
def pn532_recognized(self, tag): try: if self.in_bouncetime: logger.debug('founded tag while bouncetime -> skip') return self.last_key_time = self.current_millisecond_timestamp logger.debug("tag: %s", tag) hmm = str(tag) ID = str(hmm.split('ID=')[-1:])[2:-2] logger.debug("ID: %s", ID) if ID in self._InputPins: logger.debug("ID gefunden: %s", ID) self.last_key = ID self._fire_OnKeyDown(self.last_key, __name__) self._fire_OnKeyPressed(self.last_key, __name__) self._fire_OnKeyUp(self.last_key, __name__) doorpi.DoorPi().event_handler('OnFoundKnownTag', __name__) logger.debug("last_key is %s", self.last_key) except Exception as ex: logger.exception(ex) finally: logger.debug("pn532_recognized thread ended")
def start(self): if self.__player_id is not None: logger.trace( 'player already created as player_id %s and playing %s', self.__player_id, self.player_filename) return doorpi.DoorPi().sipphone.lib.thread_register( 'PjsuaPlayer_start_thread') self.__player_filename = doorpi.DoorPi().parse_string( self.__player_filename) logger.debug('starting player from %s', self.__player_filename) self.__player_id = doorpi.DoorPi().sipphone.lib.create_player( self.__player_filename, True) doorpi.DoorPi().sipphone.lib.player_set_pos(self.__player_id, 0) self.__slot_id = doorpi.DoorPi().sipphone.lib.player_get_slot( self.__player_id) doorpi.DoorPi().sipphone.lib.conf_connect(self.__slot_id, 0) doorpi.DoorPi().event_handler('OnPlayerStarted', __name__)
def pn532_recognized(self, tag): try: if self.in_bouncetime: logger.debug('found tag while bouncetime -> skip') return hmm = str(tag) id = str(hmm.split('ID=')[-1:])[2:-2] logger.debug('Tag: %s ID: %s', tag, id) if id in self._InputPins: logger.debug('ID %s is registered', id) self.last_key = id self.last_key_time = time.time() self._fire_OnKeyDown(self.last_key, __name__) self._fire_OnKeyPressed(self.last_key, __name__) self._fire_OnKeyUp(self.last_key, __name__) doorpi.DoorPi().event_handler('OnFoundKnownTag', __name__) except Exception as ex: logger.exception(ex) finally: logger.debug('pn532_recognized thread ended')
def save_config(self, configfile=''): if not configfile: configfile = self.config_file if not configfile: configfile = self.find_config(configfile) if not configfile: configfile = doorpi.DoorPi().parse_string( '!BASEPATH!/conf/doorpi.ini') #if not configfile: return False logger.debug("write configfile: %s", configfile) try: cfgfile = open(configfile, 'w') config = ConfigParser.ConfigParser(allow_no_value=True) for section in sorted(self.__sections.keys()): config.add_section(section) for key in sorted(self.__sections[section].keys()): config.set(section, key, self.__sections[section][key]) config.write(cfgfile) cfgfile.close() logger.info("write configfile was success: %s", configfile) return True except Exception as exp: logger.exception(exp) return False
def load_sipphone(): conf_pre = '' conf_post = '' sipphone_name = doorpi.DoorPi().config.get('SIP-Phone', 'sipphonetyp', find_first_installed_sipphone()) try: sipphone = importlib.import_module('doorpi.sipphone.from_' + sipphone_name).get( sipphone_name=sipphone_name, conf_pre=conf_pre, conf_post=conf_post) except ImportError as exp: logger.exception( 'sipphone %s not found @ sipphone.from_%s with exception %s', sipphone_name, sipphone_name, exp) logger.warning('use dummy sipphone after last exception!') sipphone = importlib.import_module('doorpi.sipphone.from_dummy').get( sipphone_name=sipphone_name, conf_pre=conf_pre, conf_post=conf_post) return sipphone
def load_single_keyboard(keyboard_name): conf_pre = keyboard_name + '_' conf_post = '' keyboard_type = doorpi.DoorPi().config.get('keyboards', keyboard_name, 'dummy').lower() store_if_not_exists = False if keyboard_type == "dummy" else True section_name = conf_pre + 'keyboard' + conf_post input_pins = doorpi.DoorPi().config.get_keys(conf_pre + 'InputPins' + conf_post) output_pins = doorpi.DoorPi().config.get_keys(conf_pre + 'OutputPins' + conf_post) bouncetime = doorpi.DoorPi().config.get_float( section_name, 'bouncetime', 2000, store_if_not_exists=store_if_not_exists) polarity = doorpi.DoorPi().config.get_int( section_name, 'polarity', 0, store_if_not_exists=store_if_not_exists) pressed_on_key_down = doorpi.DoorPi().config.get_bool( section_name, 'pressed_on_keydown', True, store_if_not_exists=store_if_not_exists) try: keyboard = importlib.import_module( 'doorpi.keyboard.from_' + keyboard_type).get( input_pins=input_pins, output_pins=output_pins, bouncetime=bouncetime, polarity=polarity, keyboard_name=keyboard_name, keyboard_type=keyboard_type, conf_pre=conf_pre, conf_post=conf_post, pressed_on_key_down=pressed_on_key_down) except ImportError as exp: logger.exception('keyboard %s not found @ keyboard.from_%s (msg: %s)', keyboard_name, keyboard_type, exp) return None return keyboard
def hangup(waittime): if waittime > 0: logger.debug('Waiting %s seconds before sending hangup request', waittime) sleep(float(waittime)) return doorpi.DoorPi().sipphone.hangup()
def destroy(self): if self.is_destroyed: return logger.debug("destroy") self._shutdown = True doorpi.DoorPi().event_handler.unregister_source(__name__, True) self.__destroyed = True
def __init__(self, input_pins, output_pins, conf_pre, conf_post, keyboard_name, bouncetime=200, polarity=0, pressed_on_key_down=True, *args, **kwargs): logger.debug( "__init__(input_pins = %s, output_pins = %s, bouncetime = %s, polarity = %s)", input_pins, output_pins, bouncetime, polarity) self.keyboard_name = keyboard_name self._polarity = polarity self._InputPins = list(map(int, input_pins)) self._OutputPins = list(map(int, output_pins)) self._pressed_on_key_down = pressed_on_key_down RPiGPIO.setwarnings(False) section_name = conf_pre + 'keyboard' + conf_post if doorpi.DoorPi().config.get(section_name, 'mode', "BOARD").upper() == "BOARD": RPiGPIO.setmode(RPiGPIO.BOARD) else: RPiGPIO.setmode(RPiGPIO.BCM) # issue 134 pull_up_down = doorpi.DoorPi().config.get(section_name, 'pull_up_down', "PUD_OFF").upper() if pull_up_down == "PUD_DOWN": pull_up_down = RPiGPIO.PUD_DOWN elif pull_up_down == "PUD_UP": pull_up_down = RPiGPIO.PUD_UP else: pull_up_down = RPiGPIO.PUD_OFF # issue #133 try: RPiGPIO.setup(self._InputPins, RPiGPIO.IN, pull_up_down=pull_up_down) except TypeError: logger.warning( 'you use an old version of GPIO library - fallback to single-register of input pins' ) for input_pin in self._InputPins: RPiGPIO.setup(input_pin, RPiGPIO.IN, pull_up_down=pull_up_down) for input_pin in self._InputPins: RPiGPIO.add_event_detect(input_pin, RPiGPIO.BOTH, callback=self.event_detect, bouncetime=int(bouncetime)) self._register_EVENTS_for_pin(input_pin, __name__) # issue #133 try: RPiGPIO.setup(self._OutputPins, RPiGPIO.OUT) except TypeError: logger.warning( 'you use an old version of GPIO library - fallback to single-register of input pins' ) for output_pin in self._OutputPins: RPiGPIO.setup(output_pin, RPiGPIO.OUT) # use set_output to register status @ dict self._OutputStatus for output_pin in self._OutputPins: self.set_output(output_pin, 0, False) self.register_destroy_action()
def time_tick(last_tick): global last_time_tick_second timestamp_now = time.time() timestamp_past = last_time_tick_second datetime_now = datetime.datetime.fromtimestamp(timestamp_now) datetime_past = datetime.datetime.fromtimestamp(timestamp_past) if datetime_now.year != datetime_past.year: doorpi.DoorPi().event_handler('OnTimeYear', __name__) if datetime_now.year % 2 is 0: doorpi.DoorPi().event_handler('OnTimeYearEvenNumber', __name__) else: doorpi.DoorPi().event_handler('OnTimeYearUnevenNumber', __name__) if datetime_now.month != datetime_past.month: doorpi.DoorPi().event_handler('OnTimeMonth', __name__) if datetime_now.month % 2 is 0: doorpi.DoorPi().event_handler('OnTimeMonthEvenNumber', __name__) else: doorpi.DoorPi().event_handler('OnTimeMonthUnevenNumber', __name__) if datetime_now.day != datetime_past.day: doorpi.DoorPi().event_handler('OnTimeDay', __name__) if datetime_now.day % 2 is 0: doorpi.DoorPi().event_handler('OnTimeDayEvenNumber', __name__) else: doorpi.DoorPi().event_handler('OnTimeDayUnevenNumber', __name__) if datetime_now.hour != datetime_past.hour: doorpi.DoorPi().event_handler('OnTimeHour', __name__) if datetime_now.hour % 2 is 0: doorpi.DoorPi().event_handler('OnTimeHourEvenNumber', __name__) else: doorpi.DoorPi().event_handler('OnTimeHourUnevenNumber', __name__) for hour in HOUR_RANGE: if hour is datetime_now.hour: doorpi.DoorPi().event_handler(('OnTimeHour{0}').format(hour), __name__) if datetime_now.minute != datetime_past.minute: doorpi.DoorPi().event_handler('OnTimeMinute', __name__) if datetime_now.minute % 2 is 0: doorpi.DoorPi().event_handler('OnTimeMinuteEvenNumber', __name__) else: doorpi.DoorPi().event_handler('OnTimeMinuteUnevenNumber', __name__) for minute in MINUTE_RANGE: if minute is datetime_now.minute: doorpi.DoorPi().event_handler( ('OnTimeMinute{0}').format(minute), __name__) if datetime_now.minute % 5 is 0: doorpi.DoorPi().event_handler('OnTimeMinuteEvery5', __name__) if datetime_now.second != datetime_past.second: doorpi.DoorPi().event_handler('OnTimeSecond', __name__) if datetime_now.second % 2 is 0: doorpi.DoorPi().event_handler('OnTimeSecondEvenNumber', __name__) else: doorpi.DoorPi().event_handler('OnTimeSecondUnevenNumber', __name__) last_time_tick_second = timestamp_now return True
def destroy_time_tick(): doorpi.DoorPi().event_handler.unregister_source(__name__, True)
def config(self): return doorpi.DoorPi().config