How to use the bellows.types.serialize function in bellows

To help you get started, we’ve selected a few bellows examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zigpy / bellows / bellows / ezsp.py View on Github external
def _ezsp_frame(self, name, *args):
        c = self.COMMANDS[name]
        data = t.serialize(args, c[1])
        frame = [self._seq & 0xFF, 0, c[0]]  # Frame control. TODO.  # Frame ID
        if self.ezsp_version >= 5:
            frame.insert(1, 0xFF)  # Legacy Frame
            frame.insert(1, 0x00)  # Frame control low byte
        if self.ezsp_version >= 8:
            frame[2] = 0x01  # EZSP v8 - FC High Byte
            frame[3] = c[0] & 0x00FF  # Extended Frame ID - LSB
            frame[4] = (c[0] & 0xFF00) >> 8  # Extended Frame ID - MSB

        return bytes(frame) + data
github zigpy / bellows / bellows / zigbee / zcl / __init__.py View on Github external
def request(self, general, command_id, schema, *args):
        if len(schema) != len(args):
            self.error("Schema and args lengths do not match in request")
            error = asyncio.Future()
            error.set_exception(ValueError("Wrong number of parameters for request, expected %d argument(s)" % len(schema)))
            return error

        aps = self._endpoint.get_aps(self.cluster_id)
        if general:
            frame_control = 0x00
        else:
            frame_control = 0x01
        data = bytes([frame_control, aps.sequence, command_id])
        data += t.serialize(args, schema)

        return self._endpoint.device.request(aps, data)
github zigpy / bellows / bellows / zigbee / zcl / __init__.py View on Github external
def reply(self, command_id, schema, *args):
        if len(schema) != len(args):
            self.error("Schema and args lengths do not match in reply")
            error = asyncio.Future()
            error.set_exception(ValueError("Wrong number of parameters for reply, expected %d argument(s)" % len(schema)))
            return error

        aps = self._endpoint.get_aps(self.cluster_id)
        frame_control = 0b1001  # Cluster reply command
        data = bytes([frame_control, aps.sequence, command_id])
        data += t.serialize(args, schema)

        return self._endpoint.device.reply(aps, data)
github zigpy / bellows / bellows / zigbee / zdo / __init__.py View on Github external
def _serialize(self, command, *args):
        aps = self._device.get_aps(profile=0, cluster=command, endpoint=0)
        data = aps.sequence.to_bytes(1, 'little')
        schema = types.CLUSTERS[command][2]
        data += t.serialize(args, schema)
        return aps, data