def event_iterator(): for major, config in event_map.items(): payload = b'\xe2\x14\x13\x01\x04\x0b\n\x02\x0c\x00\x00\x00\x00\x00\x02XXXXXXXXXXX \x01\x00\x00\x00\x00\x9c' event = parsers.LiveEvent.parse(payload) raw = event.fields.value raw.event.major = major if 'sub' in config: for minor, minor_conf in config['sub'].items(): raw.event.minor = minor yield LiveEvent(event, event_map) else: raw.event.minor = 0 yield LiveEvent(event, event_map)
def event_iterator(): for major, config in event_map.items(): payload = b"\xe2\xff\xad\x06\x14\x13\x01\x04\x0e\x10\x00\x01\x05\x00\x00\x00\x00\x00\x02Living room \x00\xcc" event = parsers.LiveEvent.parse(payload) raw = event.fields.value raw.event.major = major if "sub" in config: for minor, minor_conf in config["sub"].items(): raw.event.minor = minor yield LiveEvent(event, event_map) else: raw.event.minor = 0 yield LiveEvent(event, event_map)
def test_zone_generated_alarm_changes_match(mocker): label_provider = mocker.MagicMock(return_value="Beer") payload = binascii.unhexlify( 'e2ff1cc414130b010f2c1801030000000000024f66666963652020202020202020202000d9' ) raw = LiveEventMessage.parse(payload) event_ = LiveEvent(raw, event_map, label_provider=label_provider) assert EventTagFilter(['generated_alarm=True']).match(event_) is True assert EventTagFilter(['generated_alarm=False']).match(event_) is False assert EventTagFilter(['generated_alarm=']).match(event_) is True assert EventTagFilter(['-generated_alarm=']).match(event_) is False assert EventTagFilter(['-generated_alarm=True']).match(event_) is False assert EventTagFilter(['-generated_alarm=False']).match(event_) is True assert EventTagFilter(['zone-generated_alarm=beer']).match(event_) is True assert EventTagFilter(['zone+generated_alarm=beer']).match(event_) is False assert EventTagFilter(['generated_alarm=True+presently_in_alarm=True' ]).match(event_) is True assert EventTagFilter(['generated_alarm=True-presently_in_alarm=True' ]).match(event_) is False assert EventTagFilter(['-generated_alarm=False']).match(event_) is True with pytest.raises(AssertionError): EventTagFilter(['-=False']) with pytest.raises(AssertionError): EventTagFilter(['-""=False'])
def test_zone_generated_alarm_match(mocker): label_provider = mocker.MagicMock(return_value="Beer") payload = binascii.unhexlify( 'e2ff1cc414130b010f2c1801030000000000024f66666963652020202020202020202000d9' ) raw = LiveEventMessage.parse(payload) event_ = LiveEvent(raw, event_map, label_provider=label_provider) assert "Zone Office in alarm" == event_.message assert EventTagFilter(['zone+alarm']).match(event_) is True label_provider.assert_called_once_with("zone", 3) assert EventTagFilter(['zone-alarm']).match(event_) is False # Live event label assert EventTagFilter(['zone,alarm,"Office"']).match(event_) is True assert EventTagFilter(['zone,alarm,-"Office"']).match(event_) is False assert EventTagFilter(['zone,alarm,Office']).match(event_) is True assert EventTagFilter(['zone,alarm,-Office']).match(event_) is False assert EventTagFilter(['zone,alarm,Offic']).match(event_) is False # returned from label_provider assert EventTagFilter(['zone,alarm,Beer']).match(event_) is True assert EventTagFilter(['zone,alarm,-Beer']).match(event_) is False
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")