How to use the zigpy.zcl.foundation function in zigpy

To help you get started, we’ve selected a few zigpy 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 / zigpy / tests / test_zcl.py View on Github external
def test_read_attributes_resp_exc(cluster):
    with mock.patch.object(foundation.DATA_TYPES, "pytype_to_datatype_id") as mck:
        mck.side_effect = ValueError
        cluster.read_attributes_rsp({"hw_version": 32})
    assert cluster._endpoint.reply.call_count == 1
    assert cluster._endpoint.request.call_count == 0
    assert cluster.endpoint.reply.call_args[0][2][-3:] == b"\x03\x00\x86"
github home-assistant / home-assistant / tests / components / zha / common.py View on Github external
def make_attribute(attrid, value, status=0):
    """Make an attribute."""
    attr = zcl_f.Attribute()
    attr.attrid = attrid
    attr.value = zcl_f.TypeValue()
    attr.value.value = value
    return attr
github zigpy / zigpy / zigpy / zcl / __init__.py View on Github external
def _attr_reporting_rec(
        self,
        attribute: Union[int, str],
        min_interval: int,
        max_interval: int,
        reportable_change: int = 1,
        direction: int = 0x00,
    ) -> foundation.ConfigureReportingResponseRecord:
        if isinstance(attribute, str):
            attrid = self.attridx.get(attribute)
        else:
            attrid = attribute
        if attrid is None or attrid not in self.attributes:
            raise ValueError(f"Unknown {attribute} name of {self.ep_attribute} cluster")

        cfg = foundation.AttributeReportingConfig()
        cfg.direction = direction
        cfg.attrid = attrid
        cfg.datatype = foundation.DATA_TYPES.pytype_to_datatype_id(
            self.attributes.get(attrid, (None, foundation.Unknown))[1]
        )
        cfg.min_interval = min_interval
        cfg.max_interval = max_interval
        cfg.reportable_change = reportable_change
        return cfg
github zigpy / zigpy / zigpy / zcl / clusters / closures.py View on Github external
),
        0x0012: ("get_holiday_schedule", (t.uint8_t,), False),
        0x0013: ("clear_holiday_schedule", (t.uint8_t,), False),
        0x0014: ("set_user_type", (t.uint16_t, UserType), False),
        0x0015: ("get_user_type", (t.uint16_t,), False),
        0x0016: (
            "set_rfid_code",
            (t.uint16_t, UserStatus, UserType, t.CharacterString),
            False,
        ),
        0x0017: ("get_rfid_code", (t.uint16_t,), False),
        0x0018: ("clear_rfid_code", (t.uint16_t,), False),
        0x0019: ("clear_all_rfid_codes", (), False),
    }
    client_commands = {
        0x0000: ("lock_door_response", (foundation.Status,), True),
        0x0001: ("unlock_door_response", (foundation.Status,), True),
        0x0002: ("toggle_door_response", (foundation.Status,), True),
        0x0003: ("unlock_with_timeout_response", (foundation.Status,), True),
        0x0004: (
            "get_log_record_response",
            (
                t.uint16_t,
                t.uint32_t,
                EventType,
                OperationEventSource,
                t.uint8_t,
                t.uint16_t,
                t.Optional(t.CharacterString),
            ),
            True,
        ),
github zigpy / zigpy / zigpy / quirks / __init__.py View on Github external
async def read_attributes_raw(self, attributes, manufacturer=None):
        if not self._CONSTANT_ATTRIBUTES:
            return await super().read_attributes_raw(
                attributes, manufacturer=manufacturer
            )

        succeeded = [
            foundation.ReadAttributeRecord(
                attr, foundation.Status.SUCCESS, foundation.TypeValue()
            )
            for attr in attributes
            if attr in self._CONSTANT_ATTRIBUTES
        ]
        for record in succeeded:
            record.value.value = self._CONSTANT_ATTRIBUTES[record.attrid]

        attrs_to_read = [
            attr for attr in attributes if attr not in self._CONSTANT_ATTRIBUTES
        ]

        if not attrs_to_read:
            return [succeeded]

        results = await super().read_attributes_raw(
github zigpy / zigpy / zigpy / group.py View on Github external
async def request(self, profile, cluster, sequence, data, *args, **kwargs):
        """Send multicast request."""
        res = await self.application.mrequest(
            self.group_id,
            profile,
            cluster,
            self.application.get_endpoint_id(cluster, is_server_cluster=False),
            sequence,
            data,
        )
        return [data[2], zigpy.zcl.foundation.Status(res[0])]