def test_attribute_report(): a = foundation.AttributeReportingConfig() a.direction = 0x01 a.attrid = 0xAA55 a.timeout = 900 b = foundation.AttributeReportingConfig(a) assert a.attrid == b.attrid assert a.direction == b.direction assert a.timeout == b.timeout
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
def configure_reporting( self, attribute, min_interval, max_interval, reportable_change, manufacturer=None, ): if isinstance(attribute, str): attrid = self._attridx.get(attribute, None) else: attrid = attribute if attrid not in self.attributes or attrid is None: self.error("{} is not a valid attribute id".format(attribute)) return cfg = foundation.AttributeReportingConfig() cfg.direction = 0 cfg.attrid = attrid cfg.datatype = foundation.DATA_TYPE_IDX.get( self.attributes.get(attrid, (None, None))[1], None ) cfg.min_interval = min_interval cfg.max_interval = max_interval cfg.reportable_change = reportable_change return self._configure_reporting([cfg], manufacturer=manufacturer)
def test_attribute_reporting_config_1(): arc = foundation.AttributeReportingConfig() arc.direction = 1 arc.attrid = 99 arc.timeout = 0x7e ser = arc.serialize() arc2, data = foundation.AttributeReportingConfig.deserialize(ser) assert data == b'' assert arc2.direction == arc.direction assert arc2.timeout == arc.timeout
def configure_reporting(self, attribute, min_interval, max_interval, reportable_change): schema = foundation.COMMANDS[0x06][1] cfg = foundation.AttributeReportingConfig() cfg.direction = 0 cfg.attrid = attribute cfg.datatype = foundation.DATA_TYPE_IDX.get( self.attributes.get(attribute, (None, None))[1], None) cfg.min_interval = min_interval cfg.max_interval = max_interval cfg.reportable_change = reportable_change return self.request(True, 0x06, schema, [cfg])
def test_attribute_reporting_config_only_dir_and_attrid(): arc = foundation.AttributeReportingConfig() arc.direction = 0 arc.attrid = 99 ser = arc.serialize(_only_dir_and_attrid=True) arc2, data = foundation.AttributeReportingConfig.deserialize( ser, _only_dir_and_attrid=True ) assert data == b"" assert arc2.direction == arc.direction assert arc2.attrid == arc.attrid assert repr(arc) assert repr(arc) == repr(arc2)
def test_attribute_reporting_config_0(): arc = foundation.AttributeReportingConfig() arc.direction = 0 arc.attrid = 99 arc.datatype = 0x20 arc.min_interval = 10 arc.max_interval = 20 arc.reportable_change = 30 ser = arc.serialize() arc2, data = foundation.AttributeReportingConfig.deserialize(ser) assert data == b'' assert arc2.direction == arc.direction assert arc2.attrid == arc.attrid assert arc2.datatype == arc.datatype assert arc2.min_interval == arc.min_interval assert arc2.max_interval == arc.max_interval assert arc.reportable_change == arc.reportable_change
def configure_reporting(self, attribute, min_interval, max_interval, reportable_change): if isinstance(attribute, str): attrid = self._attridx.get(attribute, None) else: attrid = attribute if attrid not in self.attributes or attrid is None: self.error("{} is not a valid attribute id".format(attribute)) return schema = foundation.COMMANDS[0x06][1] cfg = foundation.AttributeReportingConfig() cfg.direction = 0 cfg.attrid = attrid cfg.datatype = foundation.DATA_TYPE_IDX.get( self.attributes.get(attrid, (None, None))[1], None) cfg.min_interval = min_interval cfg.max_interval = max_interval cfg.reportable_change = reportable_change return self.request(True, 0x06, schema, [cfg])
def _attr_reporting_rec( self, attribute: int | str, min_interval: int, max_interval: int, reportable_change: int = 1, direction: int = 0x00, ) -> foundation.AttributeReportingConfig: try: attr_def = self.find_attribute(attribute) except KeyError: raise ValueError( f"Unknown attribute {attribute!r} of {self} cluster") cfg = foundation.AttributeReportingConfig() cfg.direction = direction cfg.attrid = attr_def.id cfg.datatype = foundation.DATA_TYPES.pytype_to_datatype_id( attr_def.type) cfg.min_interval = min_interval cfg.max_interval = max_interval cfg.reportable_change = reportable_change return cfg