コード例 #1
0
ファイル: __init__.py プロジェクト: qingzhang15/zigpy
    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(attrs_to_read,
                                                    manufacturer=manufacturer)
        if not isinstance(results[0], list):
            for attrid in attrs_to_read:
                succeeded.append(
                    foundation.ReadAttributeRecord(attrid, results[0],
                                                   foundation.TypeValue()))
        else:
            succeeded.extend(results[0])
        return [succeeded]
コード例 #2
0
    async def read_attributes_raw(self, attributes, manufacturer=None):
        """Override wrong attribute reports from the thermostat."""
        success = []
        error = []

        if CTRL_SEQ_OF_OPER_ATTR in attributes:
            rar = foundation.ReadAttributeRecord(
                CTRL_SEQ_OF_OPER_ATTR, foundation.Status.SUCCESS, foundation.TypeValue()
            )
            rar.value.value = 0x2
            success.append(rar)

        if SYSTEM_MODE_ATTR in attributes:
            rar = foundation.ReadAttributeRecord(
                SYSTEM_MODE_ATTR, foundation.Status.SUCCESS, foundation.TypeValue()
            )
            rar.value.value = 0x4
            success.append(rar)

        if OCCUPIED_HEATING_SETPOINT_ATTR in attributes:

            _LOGGER.debug("intercepting OCC_HS")

            values = await super().read_attributes_raw(
                [CURRENT_TEMP_SETPOINT_ATTR], manufacturer=MANUFACTURER
            )

            if len(values) == 2:
                current_temp_setpoint = values[1][0]
                current_temp_setpoint.attrid = OCCUPIED_HEATING_SETPOINT_ATTR

                error.extend(values[1])
            else:
                current_temp_setpoint = values[0][0]
                current_temp_setpoint.attrid = OCCUPIED_HEATING_SETPOINT_ATTR

                success.extend(values[0])

        attributes = list(
            filter(
                lambda x: x
                not in (
                    CTRL_SEQ_OF_OPER_ATTR,
                    SYSTEM_MODE_ATTR,
                    OCCUPIED_HEATING_SETPOINT_ATTR,
                ),
                attributes,
            )
        )

        if attributes:
            values = await super().read_attributes_raw(attributes, manufacturer)

            success.extend(values[0])

            if len(values) == 2:
                error.extend(values[1])

        return success, error
コード例 #3
0
ファイル: __init__.py プロジェクト: ingeniero2019/zigpy
    def write_attributes(self,
                         attributes,
                         is_report=False,
                         manufacturer=None,
                         unsupported_attrs=[]):
        args = []
        for attrid, value in attributes.items():
            if isinstance(attrid, str):
                attrid = self._attridx[attrid]
            if attrid not in self.attributes:
                self.error("%d is not a valid attribute id", attrid)
                continue

            if is_report:
                a = foundation.ReadAttributeRecord()
                a.status = 0
            else:
                a = foundation.Attribute()

            a.attrid = t.uint16_t(attrid)
            a.value = foundation.TypeValue()

            try:
                python_type = self.attributes[attrid][1]
                a.value.type = t.uint8_t(foundation.DATA_TYPE_IDX[python_type])
                a.value.value = python_type(value)
                args.append(a)
            except ValueError as e:
                self.error(str(e))

        if is_report and unsupported_attrs:
            for attrid in unsupported_attrs:
                a = foundation.ReadAttributeRecord()
                a.attrid = attrid
                a.status = foundation.Status.UNSUPPORTED_ATTRIBUTE
                args.append(a)

        if is_report:
            schema = foundation.COMMANDS[0x01][1]
            return self.reply(True,
                              0x01,
                              schema,
                              args,
                              manufacturer=manufacturer)
        else:
            schema = foundation.COMMANDS[0x02][1]
            return self.request(True,
                                0x02,
                                schema,
                                args,
                                manufacturer=manufacturer)
コード例 #4
0
    def read_attributes_rsp(self, attributes, manufacturer=None, *, tsn=None):
        args = []
        for attrid, value in attributes.items():
            if isinstance(attrid, str):
                attrid = self.attridx[attrid]

            a = foundation.ReadAttributeRecord(
                attrid, foundation.Status.UNSUPPORTED_ATTRIBUTE,
                foundation.TypeValue())
            args.append(a)

            if value is None:
                continue

            try:
                a.status = foundation.Status.SUCCESS
                python_type = self.attributes[attrid][1]
                a.value.type = foundation.DATA_TYPES.pytype_to_datatype_id(
                    python_type)
                a.value.value = python_type(value)
            except ValueError as e:
                a.status = foundation.Status.UNSUPPORTED_ATTRIBUTE
                self.error(str(e))

        return self._read_attributes_rsp(args,
                                         manufacturer=manufacturer,
                                         tsn=tsn)
コード例 #5
0
ファイル: common.py プロジェクト: hacf-fr/home-assistant-core
 async def _read_attribute_raw(attributes, *args, **kwargs):
     result = []
     for attr_id in attributes:
         value = cluster.PLUGGED_ATTR_READS.get(attr_id)
         if value is None:
             # try converting attr_id to attr_name and lookup the plugs again
             attr_name = cluster.attributes.get(attr_id)
             value = attr_name and cluster.PLUGGED_ATTR_READS.get(attr_name[0])
         if value is not None:
             result.append(
                 zcl_f.ReadAttributeRecord(
                     attr_id,
                     zcl_f.Status.SUCCESS,
                     zcl_f.TypeValue(python_type=None, value=value),
                 )
             )
         else:
             result.append(zcl_f.ReadAttributeRecord(attr_id, zcl_f.Status.FAILURE))
     return (result,)
コード例 #6
0
 async def read_attributes_raw(self, attributes, manufacturer=None):
     """Prevent remote reads."""
     records = [
         foundation.ReadAttributeRecord(
             attr, foundation.Status.UNSUPPORTED_ATTRIBUTE,
             foundation.TypeValue()) for attr in attributes
     ]
     for record in records:
         record.value.value = self._attr_cache.get(record.attrid)
         if record.value.value is not None:
             record.status = foundation.Status.SUCCESS
     return (records, )