def onAlertMaxTimer(self): ''' Called after the sirens (or whatever alert devices you use) have reached their time limit ''' # Cancel alert devices, e.g. the sirens for alertDevice in self.alertDevices: send_command_if_different(alertDevice, scope.OFF) self.log.debug( 'Alert devices have been switched off due to they\'ve reached their time limit' )
def create_timers(start_times): """Creates Timers to transition the time of day based on the passed in list of DateTime Item names. If an Item is dated with yesterday, the Item is updated to today. The ETOD_ITEM is commanded to the current time of day if it's not already the correct state. Arguments: - start_times: list of names for DateTime Items containing the start times for each time period """ now = DateTime().now() most_recent_time = now.minusDays(1) most_recent_state = items[ETOD_ITEM] for time in start_times: item_time = DateTime(str(items[time])) trigger_time = to_today(items[time]) # Update the Item with today's date if it was for yesterday. if item_time.isBefore(trigger_time): log.debug("Item {} is yesterday, updating to today".format(time)) events.postUpdate(time, str(trigger_time)) # Get the etod state from the metadata. state = get_value(time, NAMESPACE) # If it's in the past but after most_recent, update most_recent. if trigger_time.isBefore(now) and trigger_time.isAfter( most_recent_time): log.debug( "NOW: {} start time {} is in the past but after {}".format( state, trigger_time, most_recent_time)) most_recent_time = trigger_time most_recent_state = get_value(time, NAMESPACE) # If it's in the future, schedule a Timer. elif trigger_time.isAfter(now): log.debug("FUTURE: {} Scheduleing Timer for {}".format( state, trigger_time)) timers.check(state, trigger_time, function=lambda st=state: etod_transition(st)) # If it's in the past but not after most_recent_time we can ignore it. else: log.debug( "PAST: {} start time of {} is before now {} and before {}". format(state, trigger_time, now, most_recent_time)) log.info("Created {} timers.".format(len(timers.timers))) log.info("The current time of day is {}".format(most_recent_state)) send_command_if_different(ETOD_ITEM, most_recent_state)
def onAlertMaxTimer(self): ''' Called after the sirens (or whatever alert devices you use) have reached their time limit ''' # Cancel alert devices, e.g. the sirens for alertDevice in self.alertDevices: send_command_if_different(alertDevice, scope.OFF) self.log.debug( 'Alert devices have been switched off due to they\'ve reached their time limit' ) if self.autoResetAfterAlert == True: self.log.info(u"Automatic reset Zone '{}' after Alert".format( self.name.decode('utf8'))) self.setZoneStatus(ZONESTATUS['NORMAL']) if 'onZoneResetAfterAlert' in dir(custom): custom.onZoneResetAfterAlert(self, self.getArmingMode(), self.getZoneStatus())
def onEntryTimer(self): ''' Called whenever the entry timer times out. ''' # Double check that the zone status is tripped, we can probably remove this check later if self.getZoneStatus() not in [ZONESTATUS['TRIPPED']]: raise IdeAlarmError( 'Entry Timer timed out but zone status is not tripped') self.setZoneStatus(ZONESTATUS['ALERT']) # We need to make some noise here! if not self.alarmTestMode: for alertDevice in self.alertDevices: send_command_if_different(alertDevice, scope.ON) self.log.info('You should be able to hear the sirens now...') else: self.log.info('ALARM_TEST_MODE is activated. No sirens!') post_update_if_different("Z{}_Alert_Max_Timer".format(self.zoneNumber), scope.ON)
def end_debounce(state, proxy_name, is_command): """Called at the end of the debounce period, update or commands the proxy Item with the passed in state if it's different from the proxy's current state. Arguments: state: the state to update or command the proxy Item to proxy_name: the name of the proxy Item is_command: flag that when true will cause the function to issue a command instead of an update. log: logger used for debug logging """ if is_command: log.debug("Commanding {} to {} if it's not already that state".format( proxy_name, state)) send_command_if_different(proxy_name, state) else: log.debug("Updating {} to {} if it's not already that state".format( proxy_name, state)) post_update_if_different(proxy_name, state)
def setZoneStatus(self, newZoneStatus, sendCommand=False, errorMessage=None): ''' Sets the zones current status ''' if newZoneStatus not in [ ZONESTATUS['NORMAL'], ZONESTATUS['ALERT'], ZONESTATUS['ERROR'], ZONESTATUS['TRIPPED'], ZONESTATUS['ARMING'] ]: raise IdeAlarmError('Trying to set an invalid zone status') oldZoneStatus = self._zoneStatus self._zoneStatus = newZoneStatus if newZoneStatus in [ZONESTATUS['NORMAL']]: # Cancel all timers so they won't fire post_update_if_different("Z{}_Entry_Timer".format(self.zoneNumber), scope.OFF) post_update_if_different("Z{}_Exit_Timer".format(self.zoneNumber), scope.OFF) post_update_if_different( "Z{}_Alert_Max_Timer".format(self.zoneNumber), scope.OFF) # Cancel sirens for alertDevice in self.alertDevices: send_command_if_different(alertDevice, scope.OFF) # Sync the Zone Status Item post_update_if_different(self.statusItem, newZoneStatus, sendCommand) # Call custom function if available if 'onZoneStatusChange' in dir(custom): custom.onZoneStatusChange(self, newZoneStatus, oldZoneStatus, errorMessage=errorMessage)