Пример #1
0
def test_console():
    def handler(payload: dict):
        assert payload == {
            'nwk': '0x131E',
            'ago': 335,
            'type': 'router',
            'parent': '0x1F0C'
        }

    gw = Gateway3('', '', {})
    gw.add_stats('0x00158D0000000002', handler)
    gw.z3buffer = {
        "plugin device-table print":
        "0 E265:  00158D0000000000 0  JOINED 882\r"
        "1 7585:  00158D0000000001 0  JOINED 335\r"
        "2 131E:  00158D0000000002 0  JOINED 335\r"
        "3 1F0C:  00158D0000000003 0  JOINED 247\r",
        "plugin stack-diagnostics child-table":
        "0: Sleepy 0xE265 (>)00158D0000000000 512 min debug timeout:249\r"
        "1: Sleepy 0x7585 (>)00158D0000000001 512 min debug timeout:249\r",
        "plugin stack-diagnostics neighbor-table":
        "0: 0x131E 201 1 1 3 (>)00158D0000000002\r"
        "1: 0x1F0C 172 1 0 7 (>)00158D0000000003\r",
        "buffer":
        "0: 0x1F0C -> 0x0000 (Me)\r"
        "1: 0x131E -> 0x1F0C -> 0x0000 (Me)\r"
    }
    gw.process_z3("CLI command executed: plugin concentrator print-table\r")
    assert gw.info_ts == 0
Пример #2
0
def test_motion2():
    device = {'init': {'motion': 0, 'light': 0}}

    def handler(payload: dict):
        assert payload == {'motion': 1, 'light': 0}

    gw = Gateway3('', '', {})
    gw.devices = {'blt.xxx': device}
    gw.add_update('blt.xxx', handler)

    payload = {
        "dev": {'did': 'blt.xxx', 'mac': 'AA:BB:CC:DD:EE:FF', 'pdid': 2701},
        "evt": [{"eid": 15, "edata": "0000"}],
    }
    gw.process_ble_event(payload)
Пример #3
0
def test_online():
    device = {'did': 'lumi.xxx', 'model': 'lumi.sensor_motion.aq2'}
    device.update(utils.get_device(device['model']))

    def handler(payload: dict):
        device['_'] = device['online']

    gw = Gateway3('', '', {})
    gw.devices = {'lumi.xxx': device}
    gw.add_update('lumi.xxx', handler)
    gw.process_message({
        'cmd': 'report', 'did': 'lumi.xxx',
        'params': [{'res_name': '3.1.85', 'value': 1}]
    })

    assert device['_']
Пример #4
0
def test_mi_spec_event():
    device = {'did': 'lumi.xxx', 'model': 'lumi.motion.agl04'}
    device.update(utils.get_device(device['model']))

    def handler(payload: dict):
        device['_'] = payload == {'motion': 1}

    gw = Gateway3('', '', {})
    gw.devices = {'lumi.xxx': device}
    gw.add_update('lumi.xxx', handler)
    gw.process_message({
        'cmd': 'report', 'did': 'lumi.xxx',
        'mi_spec': [{'siid': 4, 'eiid': 1, 'arguments': []}]
    })

    assert device['_']
Пример #5
0
def test_mi_spec_property():
    device = {'did': 'lumi.xxx', 'model': 'lumi.sen_ill.mgl01'}
    device.update(utils.get_device(device['model']))

    def handler(payload: dict):
        assert payload == {'battery': 86}

    gw = Gateway3('', '', {})
    gw.devices = {'lumi.xxx': device}
    gw.add_update('lumi.xxx', handler)

    payload = {
        'cmd': 'report', 'did': 'lumi.xxx',
        'mi_spec': [{'siid': 3, 'piid': 1, 'value': 3100}]
    }
    gw.process_message(payload)
Пример #6
0
def test_wrong_temperature():
    device = {'did': 'lumi.xxx', 'model': 'lumi.sensor_motion.aq2'}
    device.update(utils.get_device(device['model']))

    def handler(payload: dict):
        assert payload == {'0.1.85': 12300}

    gw = Gateway3('', '', {})
    gw.devices = {'lumi.xxx': device}
    gw.add_update('lumi.xxx', handler)

    payload = {
        'cmd': 'report', 'did': 'lumi.xxx',
        'params': [{'res_name': '0.1.85', 'value': 12300}]
    }
    gw.process_message(payload)
Пример #7
0
def _generate_gateway(model: str):
    device = {'did': 'lumi.xxx', 'model': model, 'entities': {}}
    device.update(zigbee.get_device(model))
    gw = Gateway3('', '', {})
    gw.devices = {'lumi.xxx': device}
    return gw