コード例 #1
0
ファイル: zpi_object.py プロジェクト: Hedda/zigpy-cc
    def read_parameters(cls, data: bytes, parameters):
        # print(parameters)
        buffalo = Buffalo(data)
        res = {}
        length = None
        startIndex = None
        for p in parameters:
            options = BuffaloOptions()
            name_ = p["name"]
            if name_.endswith("addr") or name_.endswith(
                    "address") or name_.endswith('addrofinterest'):
                options.is_address = True
            type_ = p["parameterType"]
            if type_ in BufferAndListTypes:
                # When reading a buffer, assume that the previous parsed parameter contains
                # the length of the buffer
                if isinstance(length, int):
                    options.length = length

                if type_ == ParameterType.LIST_ASSOC_DEV:
                    # For LIST_ASSOC_DEV, we also need to grab the startindex which is right before the length
                    if isinstance(startIndex, int):
                        options.startIndex = startIndex

            res[name_] = buffalo.read_parameter(type_, options)
            startIndex = length
            length = res[name_]

        return res
コード例 #2
0
ファイル: zpi_object.py プロジェクト: puddly/zigpy-cc
    def read_parameters(cls, data: bytes, parameters):
        # print(parameters)
        buffalo = Buffalo(data)
        res = {}
        length = None
        start_index = None
        for p in parameters:
            options = BuffaloOptions()
            name = p["name"]
            param_type = p["parameterType"]
            if param_type in BufferAndListTypes:
                if isinstance(length, int):
                    options.length = length

                if param_type == ParameterType.LIST_ASSOC_DEV:
                    if isinstance(start_index, int):
                        options.startIndex = start_index

            res[name] = buffalo.read_parameter(name, param_type, options)

            # For LIST_ASSOC_DEV, we need to grab the start_index which is
            # right before the length
            start_index = length
            # When reading a buffer, assume that the previous parsed parameter
            # contains the length of the buffer
            length = res[name]

        return res
コード例 #3
0
ファイル: zpi_object.py プロジェクト: Hedda/zigpy-cc
    def to_unpi_frame(self):
        data = Buffalo(b'')

        for p in self.parameters:
            value = self.payload[p['name']]
            data.write_parameter(p['parameterType'], value, {})

        return uart.UnpiFrame(self.type, self.subsystem, self.command_id,
                              data.buffer)
コード例 #4
0
ファイル: test_buffalo.py プロジェクト: puddly/zigpy-cc
def test_list_nighbor_lqi():
    value = [
        {
            "extPanId": EUI64.convert("d8:dd:dd:dd:d0:dd:ed:dd"),
            "extAddr": EUI64.convert("00:15:8d:00:04:21:dc:b3"),
            "nwkAddr": NWK(0xE961),
            "deviceType": 1,
            "rxOnWhenIdle": 2,
            "relationship": 2,
            "permitJoin": 2,
            "depth": 255,
            "lqi": 69,
        }
    ]
    data_out = Buffalo(b"")
    data_out.write_parameter(t.ParameterType.LIST_NEIGHBOR_LQI, value, {})
    assert (
        b"\xdd\xed\xdd\xd0\xdd\xdd\xdd\xd8\xb3\xdc!\x04\x00\x8d\x15\x00a\xe9)\x02\xffE"
        == data_out.buffer
    )

    data_in = Buffalo(data_out.buffer)
    options = BuffaloOptions()
    options.length = len(value)
    act = data_in.read_parameter("test", t.ParameterType.LIST_NEIGHBOR_LQI, options)
    assert value == act
コード例 #5
0
ファイル: test_buffalo.py プロジェクト: qingzhang15/zigpy-cc
def test_read_ieee2():
    data_in = Buffalo(ieeeAddr2["hex"])
    actual = data_in.read_parameter(t.ParameterType.IEEEADDR, {})
    assert ieeeAddr2["string"] == actual
コード例 #6
0
ファイル: test_buffalo.py プロジェクト: qingzhang15/zigpy-cc
def test_write_ieee2():
    data_out = Buffalo(b"")
    data_out.write_parameter(t.ParameterType.IEEEADDR, ieeeAddr2["string"], {})
    assert ieeeAddr2["hex"] == data_out.buffer
コード例 #7
0
def test_read_ieee():
    data_in = Buffalo(ieeeAddr1['hex'])
    actual = data_in.read_parameter(t.ParameterType.IEEEADDR, {})
    assert ieeeAddr1['string'] == actual
コード例 #8
0
def test_write_ieee():
    data_out = Buffalo(b"")
    data_out.write_parameter(t.ParameterType.IEEEADDR, ieeeAddr1['string'], {})
    assert ieeeAddr1['hex'] == data_out.buffer
コード例 #9
0
ファイル: test_buffalo.py プロジェクト: puddly/zigpy-cc
def test_write_ieee_group():
    data_out = Buffalo(b"")
    data_out.write_parameter(t.ParameterType.IEEEADDR, Group(2), {})
    assert b"\x02\x00\x00\x00\x00\x00\x00\x00" == data_out.buffer