Esempio n. 1
0
def test_door_user2():
    payload = b'\xe2\xff\xad\x06\x14\x13\x01\x04\x0e\x10\x06\x01\x05\x01\x00\x00\x00\x00\x02Living room     \x00\xd3'

    raw = LiveEvent.parse(payload)

    def label_provider(type, id):
        if type == 'user':
            assert id == 5
            return 'Test'
        elif type == 'partition':
            assert id == 5
            return 'First floor'
        elif type == 'door':
            assert id == 5
            return 'Door 1'
        else:
            assert False

    # monkey patch
    event_map[6]['message'] = 'User {@user#minor} access on door {@door}'

    event = Event()
    event.from_live_event(event_map, raw, label_provider=label_provider)

    assert "User Test access on door Door 1" == event.message
    print(event)
Esempio n. 2
0
def test_event_winload_connected():
    payload = b'\xe2\xff\xaa\xb0\x14\x13\x01\x04\x0b$-\x00\x04\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xc7'

    raw = LiveEvent.parse(payload)
    event = Event()
    event.from_live_event(event_map, raw)
    assert "Special events: WinLoad in (connected)" == event.message
    print(event)
Esempio n. 3
0
def test_disconnect_event():
    payload = b'\xe0\xff\xe1\xe8\x14\x13\x02\x11\x0f%-\x00\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00H'

    raw = LiveEvent.parse(payload)
    event = Event()
    event.from_live_event(event_map, raw)
    assert "Special events: WinLoad out (disconnected)" == event.message
    print(event)
Esempio n. 4
0
def test_event_clock_restore():
    payload = b'\xe2\xff\xaa\xb1\x14\x13\x01\x04\x0b$%\x00\x06\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xc2'

    raw = LiveEvent.parse(payload)
    event = Event()
    event.from_live_event(event_map, raw)
    assert "Trouble restore: Clock loss restore" == event.message
    print(event)
Esempio n. 5
0
    def _on_event(self, event: Event):
        if cfg.LOGGING_DUMP_EVENTS:
            logger.debug("LiveEvent: {}".format(event))

        event.call_hook(storage=self.storage, alarm=self)

        if isinstance(event, LiveEvent):
            self._update_partition_states()
Esempio n. 6
0
def test_property_map_bad():
    change = dict(property='does_not_exist',
                  value=True,
                  partition=None,
                  time=time.time(),
                  type='system',
                  label='alarm_in_memory')
    evt = Event()
    r = evt.from_change(change=change, property_map=Panel_EVO192.property_map)
    assert not r
Esempio n. 7
0
def test_zone_open():
    payload = b'\xe2\xff\xad\x06\x14\x13\x01\x04\x0e\x10\x01\x01\x05\x00\x00\x00\x00\x00\x02Living room     \x00\xcd'

    raw = LiveEvent.parse(payload)
    event = Event()
    event.from_live_event(event_map, raw, label_provider=label_provider)

    assert event.change == {'open': True}
    assert "Zone Living room open" == event.message
    print(event)
Esempio n. 8
0
def test_property_map_bad():
    change = dict(property='dcd',
                  value=3.33,
                  partition=None,
                  time=time.time(),
                  type='system',
                  label='power')
    evt = Event()
    r = evt.from_change(change=change, property_map=Panel.property_map)
    assert not r
Esempio n. 9
0
def test_disarm_partition0():
    hex = b'e2141301040b09020b0100000000025858585858585858585858202020202001000000009b' # {'type': 'Partition', 'minor': (11, 'Disarm partition'), 'major': (2, 'Partition status')}
    payload = binascii.unhexlify(hex)

    raw = LiveEvent.parse(payload)
    event = Event()
    event.from_live_event(event_map, raw, None)

    assert event.message == "Partition [partition:2]: Disarmed"
    print(event)
Esempio n. 10
0
def test_partition_arm_message():
    change = dict(property='arm',
                  value=True,
                  partition=1,
                  time=time.time(),
                  type='partition',
                  label='Fridge')
    evt = Event()
    r = evt.from_change(change=change, property_map=Panel.property_map)
    assert r
    assert evt.message == "Partition Fridge is armed"
Esempio n. 11
0
def test_property(type, property, value, partition, label):
    change = dict(property=property,
                  value=value,
                  partition=partition,
                  time=time.time(),
                  type=type,
                  label=label)
    evt = Event()
    r = evt.from_change(change=change, property_map=Panel.property_map)

    assert r
    assert len(evt.message) > 0
Esempio n. 12
0
def test_property_map_value():

    change = dict(property='dc',
                  value=3.33,
                  partition=None,
                  time=time.time(),
                  type='system',
                  label='power')
    evt = Event()
    r = evt.from_change(change=change, property_map=Panel.property_map)
    assert r
    assert evt.message == "DC voltage is 3.33V"
Esempio n. 13
0
def test_door_user():
    payload = b'\xe2\xff\xad\x06\x14\x13\x01\x04\x0e\x10\x06\x01\x05\x01\x00\x00\x00\x00\x02Living room     \x00\xd3'

    raw = LiveEvent.parse(payload)

    # monkey patch
    event_map[6]['message'] = 'User {@user} access on door {@door}'

    event = Event()
    event.from_live_event(event_map, raw, label_provider=label_provider)

    assert "User Test access on door Door 1" == event.message
    print(event)
Esempio n. 14
0
def test_disarm_partition1():
    hex = b'e2141301040b09020b0100000000025858585858585858585858202020202001000000009b' # {'type': 'Partition', 'minor': (11, 'Disarm partition'), 'major': (2, 'Partition status')}
    payload = binascii.unhexlify(hex)

    # monkey patch
    event_map[2]['sub'][11]['message']='Disarm partition {name}'

    def label_provider(type, id):
        assert type == 'partition'
        assert id == 2
        return 'Partition 2'

    raw = LiveEvent.parse(payload)
    event = Event()
    event.from_live_event(event_map, raw, label_provider)

    print(event)

    assert event.message == "Partition Partition 2: Disarm partition Partition 2"
Esempio n. 15
0
def test_zone_ok():
    payload = b'\xe2\xff\xad\x06\x14\x13\x01\x04\x0e\x10\x00\x01\x05\x00\x00\x00\x00\x00\x02Living room     \x00\xcc'

    raw = LiveEvent.parse(payload)

    def label_provider(type, id):
        assert type == 'partition'
        assert id == 1
        return 'First floor'

    # monkey patch
    event_map[0]['message'] = 'Zone {label} OK in partition {@partition}'

    event = Event()
    event.from_live_event(event_map, raw, label_provider=label_provider)

    assert event.change == {'open': False}

    assert "Zone Living room OK in partition First floor" == event.message
    print(event)
Esempio n. 16
0
async def test_handle_panel_event(mocker):
    interface = get_interface(mocker)
    try:
        await asyncio.sleep(0.01)

        event = Event()
        event.label = "Test"
        event.minor = 0
        event.major = 0
        event.time = datetime.datetime(2019, 10, 18, 17, 15)

        interface._handle_panel_event(event)
        await asyncio.sleep(0.01)
        interface.mqtt.publish.assert_called_once_with('paradox/events/raw',
                                                       json.dumps({"additional_data": {}, "change": {},
                                                                   "key": "None,Test,", "label": "Test",
                                                                   "level": "NOTSET", "major": 0, "message": "",
                                                                   "minor": 0, "tags": [],
                                                                   "time": "2019-10-18T17:15:00", "timestamp": 0,
                                                                   "type": None}, sort_keys=True),
                                                       0, True)
    finally:
        interface.stop()
        interface.join()
        assert not interface.is_alive()
Esempio n. 17
0
def test_tag_match():
    event = Event()
    event.level = EventLevel.INFO
    event.tags = ["arm", "restore"]
    event.type = "partition"

    assert EventTagFilter(["partition+arm"]).match(event) is True
    assert EventTagFilter(["partition+arm+restore"]).match(event) is True
    assert EventTagFilter(["partition"]).match(event) is True
    assert EventTagFilter(["arm"]).match(event) is True
    assert EventTagFilter(["arm-zone"]).match(event) is True
    assert EventTagFilter(["arm-partition"]).match(event) is False
    assert EventTagFilter(["arm-zone+restore+partition"]).match(event) is True
    assert EventTagFilter(["zone"]).match(event) is False
    assert EventTagFilter(["zone", "arm"]).match(event) is True

    assert EventTagFilter(["partition,arm"]).match(event) is True
    assert EventTagFilter(["partition, arm"]).match(event) is True
    assert EventTagFilter(["partition, -arm"]).match(event) is False

    assert EventTagFilter(["live,partition,arm"]).match(event) is False
    assert EventTagFilter(["change,partition,arm"]).match(event) is False

    event.level = EventLevel.DEBUG
    assert EventTagFilter(["partition+arm"]).match(event) is False
Esempio n. 18
0
async def test_handle_panel_event(mocker):
    interface = BasicMQTTInterface()
    interface.mqtt = mocker.MagicMock()

    event = Event()
    event.label = "Test"
    event.minor = 0
    event.major = 0
    event.time = datetime.datetime(2019, 10, 18, 17, 15)

    interface._handle_panel_event(event)
    interface.mqtt.publish.assert_called_once_with(
        'paradox/events/raw',
        json.dumps(
            {
                "additional_data": {},
                "change": {},
                "key": "None,Test,",
                "label": "Test",
                "level": "NOTSET",
                "major": 0,
                "message": "",
                "minor": 0,
                "tags": [],
                "time": "2019-10-18T17:15:00",
                "timestamp": 0,
                "type": None
            },
            sort_keys=True), 0, True)
Esempio n. 19
0
def test_tag_match():
    event = Event()
    event.level = EventLevel.INFO
    event.tags = ['arm', 'restore']
    event.type = 'partition'

    assert EventTagFilter(['partition+arm']).match(event) is True
    assert EventTagFilter(['partition+arm+restore']).match(event) is True
    assert EventTagFilter(['partition']).match(event) is True
    assert EventTagFilter(['arm']).match(event) is True
    assert EventTagFilter(['arm-zone']).match(event) is True
    assert EventTagFilter(['arm-partition']).match(event) is False
    assert EventTagFilter(['arm-zone+restore+partition']).match(event) is True
    assert EventTagFilter(['zone']).match(event) is False
    assert EventTagFilter(['zone', 'arm']).match(event) is True

    assert EventTagFilter(['partition,arm']).match(event) is True
    assert EventTagFilter(['partition, arm']).match(event) is True
    assert EventTagFilter(['partition, -arm']).match(event) is False

    event.level = EventLevel.DEBUG
    assert EventTagFilter(['partition+arm']).match(event) is False