Пример #1
0
def test_mi_curtain():
    device = XDevice(ZIGBEE, 'lumi.curtain.acn002', ZDID, ZMAC, ZNWK)
    assert device.info.name == 'Aqara Roller Shade E1 CN'
    device.setup_converters()

    p = device.decode_lumi([
        {"siid": 2, "piid": 1, "value": 0},
        {"siid": 2, "piid": 3, "value": 0},
        {"siid": 2, "piid": 4, "value": 60},
        {"siid": 2, "piid": 5, "value": 60}
    ])
    assert p == {'position': 60, 'target_position': 60}

    p = device.decode_lumi([
        {"siid": 3, "piid": 1, "value": 1},
        {"siid": 3, "piid": 2, "value": 7317},
        {"siid": 3, "piid": 3, "value": 0},
        {"siid": 3, "piid": 4, "value": 48}
    ])
    assert p == {
        'battery': 48, 'battery_charging': False, 'battery_low': False,
        'battery_voltage': 7317
    }

    p = device.decode_lumi([{"siid": 2, "piid": 6, "value": 0}])
    assert p == {'run_state': 'closing'}

    p = device.decode_lumi([{"siid": 2, "piid": 2, "value": 1}])
    assert p == {'motor': 'close'}

    p = device.encode({'motor': 'open'})
    assert p == {"mi_spec": [{'siid': 2, 'piid': 2, 'value': 2}]}

    p = device.encode({"position": 60})
    assert p == {'mi_spec': [{'siid': 2, 'piid': 4, 'value': 60}]}
Пример #2
0
def test_lumi_encode():
    device = XDevice(ZIGBEE, 'lumi.plug', ZDID, ZMAC, ZNWK)
    device.setup_converters()

    p = device.encode({'plug': True})
    assert p == {"params": [{'res_name': '4.1.85', 'value': 1}]}

    device = XDevice(ZIGBEE, 'lumi.switch.l0agl1', ZDID, ZMAC, ZNWK)
    assert device.info.name == 'Aqara Relay T1 EU (no N)'
    device.setup_converters()

    p = device.encode({'switch': True})
    assert p == {'mi_spec': [{'siid': 2, 'piid': 1, 'value': True}]}
Пример #3
0
def test_lumi_curtain():
    device = XDevice(ZIGBEE, 'lumi.curtain', ZDID, ZMAC, ZNWK)
    assert device.info.name == 'Aqara Curtain'
    device.setup_converters()

    p = device.decode_lumi([{'res_name': '14.2.85', 'value': 1}])
    assert p == {'motor': 'open'}

    p = device.decode_lumi([{"res_name": "1.1.85", "value": 100}])
    assert p == {'position': 100}

    p = device.encode({"motor": "stop"})
    assert p == {"params": [{'res_name': '14.2.85', 'value': 2}]}

    p = device.encode({"position": 48})
    assert p == {"params": [{'res_name': '1.1.85', 'value': 48}]}
Пример #4
0
def test_gateway():
    device = XDevice(GATEWAY, "lumi.gateway.mgl03", DID, MAC)
    assert device.info.name == "Xiaomi Gateway 3"
    device.setup_converters()

    p = device.decode_lumi([{"res_name": "8.0.2109", "value": 60}])
    assert p == {'pair': True}

    p = device.encode({'pair': False})
    assert p == {"params": [{"res_name": "8.0.2109", "value": 0}]}

    # old zigbee pairing
    p = device.decode_lumi([{
        "res_name": "8.0.2111",
        "value": {
            "code": 0,
            "install_code": "",
            "mac": "",
            "message": "no data"
        },
        "error_code": 0
    }])
    assert p

    # _sync.zigbee3_get_install_code error
    p = device.decode_lumi([{
        "res_name": "8.0.2111",
        "value": {
            "code": -4001002,
            "install_code": "",
            "mac": "",
            "message": "no data"
        },
        "error_code": 0
    }])
    assert p

    # zigbee3 pairing
    p = device.decode_lumi([{
        "res_name": "8.0.2111",
        "value": {
            "code": 0,
            "install_code": "<36 hex>",
            "mac": "<16 hex>"
        },
        "error_code": 0
    }])
    assert p

    p = device.decode_lumi([{
        "res_name":
        "8.0.2155",
        "value":
        "{\"cloud_link\":1,\"tz_updated\":\"GMT3\"}"
    }])
    assert p == {'cloud_link': True}
Пример #5
0
def test_climate():
    device = XDevice(ZIGBEE, "lumi.airrtc.tcpecn02", ZDID, ZMAC, ZNWK)
    assert device.info.name == 'Aqara Thermostat S2 CN'
    device.setup_converters()

    p = device.decode_lumi([
        {"res_name": "14.2.85", "value": 268435455},
        {"res_name": "14.8.85", "value": 15},
        {"res_name": "14.9.85", "value": 255},
        {"res_name": "14.10.85", "value": 15},
        {"res_name": "3.2.85", "value": 63},
        {"res_name": "3.1.85", "value": 0}
    ])
    assert p == {
        'climate': 268435455, 'hvac_mode': 'off', 'target_temp': 0,
        'fan_mode': None, 'current_temp': 63
    }

    params = [
        {"res_name": "14.2.85", "value": 288366197},
        {"res_name": "14.8.85", "value": 1},
        {"res_name": "14.9.85", "value": 30},
        {"res_name": "14.10.85", "value": 3},
        {"res_name": "3.2.85", "value": 29},
        {"res_name": "3.1.85", "value": 1}
    ]
    p = device.decode_lumi(params)
    assert p == {
        'climate': 288366197, 'hvac_mode': 'cool', 'target_temp': 30,
        'fan_mode': 'auto', 'current_temp': 29
    }

    x = params[0]["value"]
    p = device.encode({"climate": {"climate": x, "fan_mode": "low"}})
    y = p["params"][0]["value"]
    assert x != y
    p = device.encode({"climate": {"climate": y, "fan_mode": "auto"}})
    y = p["params"][0]["value"]
    assert x == y
Пример #6
0
def test_brightness():
    device = XDevice(MESH, 3164, "123", "112233aabbcc")
    device.setup_converters()

    p = device.encode({'light': True, 'brightness': 15.0, 'color_temp': 300})
    assert p['mi_spec'] == [{
        'siid': 2,
        'piid': 1,
        'value': True
    }, {
        'siid': 2,
        'piid': 2,
        'value': 6
    }, {
        'siid': 2,
        'piid': 3,
        'value': 3333
    }]