コード例 #1
0
def test_invalid_type2():
    if version.major == 2 and version.minor == 7:
        with pytest.raises(TypeError) as e:
            assert decode(u"02670113")
        assert str(
            e.value
        ) == "Payload must be hex encoded string. Provided type: <type 'unicode'>"
    else:
        with pytest.raises(TypeError) as e:
            assert decode(b"02670113")
        assert str(
            e.value
        ) == "Payload must be hex encoded string. Provided type: <class 'bytes'>"
コード例 #2
0
def test_invalid_type():
    if version.major == 2 and version.minor == 7:
        with pytest.raises(TypeError) as e:
            assert decode(13)
        assert str(
            e.value
        ) == "Payload must be hex encoded string. Provided type: <type 'int'>"
    else:
        with pytest.raises(TypeError) as e:
            assert decode(13)
        assert str(
            e.value
        ) == "Payload must be hex encoded string. Provided type: <class 'int'>"
コード例 #3
0
ファイル: serial2idb.py プロジェクト: AllWize/allwize
def parse(data):

    parts = data.rstrip().split(",")
    if len(parts) != 4:
        print("[PARSER] Wrong number of fields")
        return
    device = parts[0]
    counter = parts[1]
    rssi = parts[2]
    payload = parts[3]
    fields = decode(payload)

    send("rssi,uid=%s value=%s" % (device, rssi))
    for f in fields:
        name = f["name"].replace(' ', '_').lower()
        if isinstance(f["value"], dict):
            data = "%s,uid=%s" % (name, device)
            sep = " "
            for k, v in f["value"].items():
                name = k.replace(' ', '_').lower()
                data = "%s%s%s=%s" % (data, sep, name, v)
                sep = ","
            send(data)

        else:
            send("%s,uid=%s value=%s" % (name, device, f["value"]))
コード例 #4
0
def test_gyrometer():
    expected = [{
        'channel': 153,
        'name': 'Gyrometer',
        'value': {
            'x': 51.57,
            'y': 141.84,
            'z': -272.6
        }
    }]
    result = decode("9986142537689584")
    assert result == expected
コード例 #5
0
def test_accelerometer():
    expected = [{
        'channel': 83,
        'name': 'Accelerometer',
        'value': {
            'x': 4.66,
            'y': 22.136,
            'z': -28.381
        }
    }]
    result = decode("5371123456789123")
    assert result == expected
コード例 #6
0
def test_combination():
    expected = [{
        'channel': 3,
        'name': 'Temperature Sensor',
        'value': -12.5
    }, {
        'channel': 7,
        'name': 'Humidity Sensor',
        'value': 17.0
    }]
    result = decode("0367FF83076822")
    assert result == expected
コード例 #7
0
def test_gps():
    expected = [{
        'channel': 17,
        'name': 'GPS Location',
        'value': {
            'lat': -33.8678,
            'long': -63.987,
            'alt': 10.0
        }
    }]
    result = decode("1188FAD50AF63C820003E8")
    assert result == expected
コード例 #8
0
def test_combinatio2n():
    expected = [{
        'channel': 17,
        'name': 'GPS Location',
        'value': {
            'lat': -33.8678,
            'long': -63.987,
            'alt': 10.0
        }
    }, {
        'channel': 17,
        'name': 'Analog Output',
        'value': -23.0
    }]
    result = decode("1188FAD50AF63C820003E81103F704")
    assert result == expected
コード例 #9
0
ファイル: serial2mqtt.py プロジェクト: AllWize/allwize
def parse(data):

    parts = data.rstrip().split(",")
    if len(parts) != 4:
        print("[PARSER] Wrong number of fields")
        return
    device = parts[0]
    counter = parts[1]
    rssi = parts[2]
    payload = parts[3]
    fields = decode(payload)

    for f in fields:
        name = f["name"].replace(' ', '_').lower()
        if isinstance(f["value"], dict):
            for k, v in f["value"].items():
                name = k.replace(' ', '_').lower()
                topic = "device/%s/%s" % (device, name)
                send(topic, v)
                
        else:
            topic = "device/%s/%s" % (device, name)
            send(topic, f["value"])
コード例 #10
0
def test_temp():
    expected = [{'channel': 3, 'name': 'Temperature Sensor', 'value': 27.2}]
    result = decode("03670110")
    assert result == expected
コード例 #11
0
def test_presence():
    expected = [{'channel': 119, 'name': 'Presence Sensor', 'value': 3}]
    result = decode("776603")
    assert result == expected
コード例 #12
0
def test_illuminance():
    expected = [{'channel': 23, 'name': 'Illuminance Sensor', 'value': 29509}]
    result = decode("17657345")
    assert result == expected
コード例 #13
0
def test_analog_in():
    expected = [{'channel': 5, 'name': 'Analog Input', 'value': 48.84}]
    result = decode("05021314")
    assert result == expected
コード例 #14
0
def test_invalid_length():
    with pytest.raises(ValueError) as e:
        assert decode("026711")
    assert str(
        e.value
    ) == "The length on the payload 026711 is 6 doesn't correspond to expected 8"
コード例 #15
0
def test_invalid_key(capsys):
    a = decode("0167023302991233")
    captured = capsys.readouterr()
    assert captured.out == "[ERROR]: Decoding failed or incomplete. Unrecognized sensor type: 99\n"
    assert a == [{'channel': 1, 'name': 'Temperature Sensor', 'value': 56.3}]
コード例 #16
0
def test_temp_signed():
    expected = [{'channel': 3, 'name': 'Temperature Sensor', 'value': -12.5}]
    result = decode("0367FF83")
    assert result == expected
コード例 #17
0
def test_humidity():
    expected = [{'channel': 7, 'name': 'Humidity Sensor', 'value': 17.0}]
    result = decode("076822")
    assert result == expected
コード例 #18
0
def test_analog_out():
    expected = [{'channel': 17, 'name': 'Analog Output', 'value': 54.61}]
    result = decode("11031555")
    assert result == expected
コード例 #19
0
def test_barometer():
    expected = [{'channel': 38, 'name': 'Barometer', 'value': 856.8}]
    result = decode("26732178")
    assert result == expected
コード例 #20
0
def test_analog_in_signed():
    expected = [{'channel': 5, 'name': 'Analog Input', 'value': -78.21}]
    result = decode("0502E173")
    assert result == expected
コード例 #21
0
def test_digital_out():
    expected = [{'channel': 17, 'name': 'Digital Output', 'value': 34}]
    result = decode("110122")
    assert result == expected
コード例 #22
0
def test_digital_in():
    expected = [{'channel': 9, 'name': 'Digital Input', 'value': 34}]
    result = decode("090022")
    assert result == expected
コード例 #23
0
def decode_payload(out):
    return decode(out.strip().decode('utf-8'))
コード例 #24
0
def test_analog_out_signed():
    expected = [{'channel': 17, 'name': 'Analog Output', 'value': -23.0}]
    result = decode("1103F704")
    assert result == expected