def handle_event_message(self, message: Container = None): """Process cfg.Live Event Message and dispatch it to the interface module""" try: try: evt = LiveEvent( event=message, event_map=self.panel.event_map, label_provider=self.get_label, ) except AssertionError as e: logger.debug("Error creating event") return element = self.storage.get_container_object(evt.type, evt.id) # Temporary to catch labels/properties in wrong places # TODO: REMOVE if message is not None: if not evt.id: logger.debug( "Missing element ID in {}/{}, m/m: {}/{}, message: {}". format( evt.type, evt.label or "?", evt.major, evt.minor, evt.message, )) else: if not element: logger.warning( "Missing element with ID {} in {}/{}".format( evt.id, evt.type, evt.label)) else: for k in evt.change: if k not in element: logger.warning( "Missing property {} in {}/{}".format( k, evt.type, evt.label)) if evt.label != element.get("label"): logger.warning( "Labels differ {} != {} in {}/{}".format( element.get("label"), evt.label, evt.type, evt.label)) # Temporary end # The event has changes. Update the state if len(evt.change) > 0 and element: self.storage.update_container_object(evt.type, evt.id, evt.change) ps.sendEvent(evt) except: logger.exception("Handle live event")
def _on_property_change(self, change: Change): if change.initial: return try: event = ChangeEvent(change_object=change, property_map=self.panel.property_map, label_provider=self.get_label) if cfg.LOGGING_DUMP_EVENTS: logger.debug("ChangeEvent: {}".format(event)) ps.sendEvent(event) except AssertionError: logger.debug("Could not create event from change")
def handle_event(self, message: Container=None): """Process cfg.Live Event Message and dispatch it to the interface module""" try: evt = event.Event() r = False logger.debug("Handle event from panel message: {}".format(message)) r = evt.from_live_event(self.panel.event_map, event=message, label_provider=self.get_label) if r: if len(evt.change) == 0: # Publish event ps.sendEvent(evt) else: logger.debug("Error creating event") return logger.debug("Event: {}".format(evt)) # Temporary to catch labels/properties in wrong places # TODO: REMOVE if message is not None: if evt.type in self.data: if not evt.id: logger.warn("Missing element ID in {}/{}, m/m: {}/{}, message: {}".format(evt.type, evt.label or '?', evt.major, evt.minor, evt.message)) else: el = self.data[evt.type].get(evt.id) if not el: logger.warn("Missing element with ID {} in {}/{}".format(evt.id, evt.type, evt.label)) else: for k in evt.change: if k not in el: logger.warn("Missing property {} in {}/{}".format(k, evt.type, evt.label)) if evt.label != el.get("label"): logger.warn( "Labels differ {} != {} in {}/{}".format(el.get("label"), evt.label, evt.type, evt.label)) else: logger.warn("Missing type {} for event: {}.{} {}".format(evt.type, evt.major, evt.minor, evt.message)) # Temporary end # The event has changes. Update the state if len(evt.change) > 0 and evt.type in self.data and evt.id in self.data[evt.type]: self.update_properties(evt.type, evt.id, evt.change) except Exception as e: logger.exception("Handle event")
def update_properties(self, element_type: str, type_key: str, change: dict, publish=PublishPropertyChange.DEFAULT): try: elements = self.data[element_type] except KeyError: logger.debug('Error: "%s" key is missing from data' % element_type) return if type_key not in elements: return # Publish changes and update state for property_name, property_value in change.items(): if property_name.startswith('_'): # skip private properties continue # Virtual property "Trouble" # True if element has ANY type of alarm if 'trouble' in property_name and property_name !='trouble': if property_value: self.update_properties(element_type, type_key, dict(trouble=True), publish=publish) else: r = False for kk, vv in elements[type_key].items(): if 'trouble' in kk: r = r or elements[type_key][kk] self.update_properties(element_type, type_key, dict(trouble=r), publish=publish) # Standard processing of changes if property_name in elements[type_key]: old = elements[type_key][property_name] if old != change[property_name] \ or publish == PublishPropertyChange.YES \ or cfg.PUSH_UPDATE_WITHOUT_CHANGE: logger.debug("Change {}/{}/{} from {} to {}".format(element_type, elements[type_key]['key'], property_name, old, property_value)) elements[type_key][property_name] = property_value ps.sendChange(element_type, elements[type_key]['key'], property_name, property_value) # Ignore change if is a generic trouble. if not (property_name == 'trouble' and element_type == 'system'): if element_type == 'partition': partition = elements[type_key]['key'] else: partition = "" evt_change = {'property': property_name, 'value': property_value, 'type': element_type, 'partition': partition, 'label': elements[type_key]['key'], 'time': int(time.time())} evt = event.Event() r = evt.from_change(property_map=self.panel.property_map, change=evt_change) if r: logger.debug("Event: {}".format(evt)) ps.sendEvent(evt) else: logger.warn("Could not create event from change") else: elements[type_key][property_name] = property_value # Initial value, do not notify suppress = 'trouble' not in property_name ps.sendChange(element_type, elements[type_key]['key'], property_name, property_value, initial=suppress)