/// <summary> /// Processes a list of attribute status reports for this cluster /// /// <param name="reports">List of ReadAttributeStatusRecord</param> /// </summary> public void HandleAttributeStatus(List <ReadAttributeStatusRecord> records) { foreach (ReadAttributeStatusRecord record in records) { if (record.Status != ZclStatus.SUCCESS) { //logger.debug("{}: Error reading attribute {} in cluster {} - {}", zigbeeEndpoint.getEndpointAddress(), // record.getAttributeIdentifier(), clusterId, record.getStatus()); continue; } ZclAttribute attribute = null; if (_attributes.TryGetValue(record.AttributeIdentifier, out attribute) == true) { if (attribute == null) { //logger.debug("{}: Unknown attribute {} in cluster {}", zigbeeEndpoint.getEndpointAddress(), // record.getAttributeIdentifier(), clusterId); } else { attribute.UpdateValue(_normalizer.NormalizeZclData(attribute.ZclDataType, record.AttributeValue)); NotifyAttributeListener(attribute); } } } }
/** * Read an attribute * * @param attribute the {@link ZclAttribute} to read * @return */ protected object ReadSync(ZclAttribute attribute) { //logger.debug("readSync request: {}", attribute); CommandResult result; try { result = Read(attribute).Result; } catch (TaskCanceledException e) // TODO: Check if this is the right exception to catch here { //logger.debug("readSync interrupted"); return(null); } catch (Exception e) { //logger.debug("readSync exception ", e); return(null); } if (!result.IsSuccess()) { return(null); } ReadAttributesResponse response = result.GetResponse <ReadAttributesResponse>(); if (response.Records[0].Status == ZclStatus.SUCCESS) { ReadAttributeStatusRecord attributeRecord = response.Records[0]; return(_normalizer.NormalizeZclData(attribute.ZclDataType, attributeRecord.AttributeValue)); } return(null); }
/** * Notify attribute listeners of an updated {@link ZclAttribute}. * * @param attribute the {@link ZclAttribute} to notify */ private void notifyAttributeListener(ZclAttribute attribute) { foreach (IZclAttributeListener listener in _attributeListeners) { // NotificationService.execute(new Runnable() { // @Override // public void run() // { // listener.attributeUpdated(attribute); // } //}); } }
/// <summary> /// Gets the reporting configuration for an attribute /// /// <param name="attribute">the ZclAttribute on which to enable reporting</param> /// <returns>command Task CommandResult</returns> /// </summary> public Task <CommandResult> GetReporting(ZclAttribute attribute) { ReadReportingConfigurationCommand command = new ReadReportingConfigurationCommand(); command.ClusterId = _clusterId; AttributeRecord record = new AttributeRecord(); record.AttributeIdentifier = attribute.Id; record.Direction = 0; command.Records = new List <AttributeRecord>(new[] { record }); command.DestinationAddress = _zigbeeEndpoint.GetEndpointAddress(); return(Send(command)); }
/// <summary> /// Processes a list of attribute reports for this cluster /// /// <param name="reports">List of AttributeReport</param> /// </summary> public void HandleAttributeReport(List <AttributeReport> reports) { foreach (AttributeReport report in reports) { ZclAttribute attribute = _attributes[report.AttributeIdentifier]; if (attribute == null) { //logger.debug("{}: Unknown attribute {} in cluster {}", zigbeeEndpoint.getEndpointAddress(), // report.getAttributeIdentifier(), clusterId); } else { attribute.UpdateValue(_normalizer.NormalizeZclData(attribute.ZclDataType, report.AttributeValue)); NotifyAttributeListener(attribute); } } }
/// <summary> /// Configures the reporting for the specified attribute ID for analog attributes. /// /// minInterval: /// The minimum reporting interval field is 16 bits in length and shall contain the /// minimum interval, in seconds, between issuing reports of the specified attribute. /// If minInterval is set to 0x0000, then there is no minimum limit, unless one is /// imposed by the specification of the cluster using this reporting mechanism or by /// the applicable profile. /// /// maxInterval: /// The maximum reporting interval field is 16 bits in length and shall contain the /// maximum interval, in seconds, between issuing reports of the specified attribute. /// If maxInterval is set to 0xffff, then the device shall not issue reports for the specified /// attribute, and the configuration information for that attribute need not be /// maintained. /// /// reportableChange: /// The reportable change field shall contain the minimum change to the attribute that /// will result in a report being issued. This field is of variable length. For attributes /// with 'analog' data type the field has the same data type as the attribute. The sign (if any) of the reportable /// change field is ignored. /// /// <param name="attribute">the ZclAttribute to configure reporting</param> /// <param name="minInterval">the minimum reporting interval</param> /// <param name="maxInterval">the maximum reporting interval</param> /// <param name="reportableChange">the minimum change required to report an update</param> /// <returns>command Task CommandResult</returns> /// </summary> public Task <CommandResult> SetReporting(ZclAttribute attribute, ushort minInterval, ushort maxInterval, object reportableChange) { ConfigureReportingCommand command = new ConfigureReportingCommand(); command.ClusterId = _clusterId; AttributeReportingConfigurationRecord record = new AttributeReportingConfigurationRecord(); record.Direction = 0; record.AttributeIdentifier = attribute.Id; record.AttributeDataType = attribute.ZclDataType; record.MinimumReportingInterval = minInterval; record.MaximumReportingInterval = maxInterval; record.ReportableChange = reportableChange; record.TimeoutPeriod = 0; command.Records = new List <AttributeReportingConfigurationRecord>(new[] { record }); command.DestinationAddress = _zigbeeEndpoint.GetEndpointAddress(); return(Send(command)); }
/// <summary> /// Read an attribute /// /// <param name="attribute">the ZclAttribute to read</param> /// </summary> protected object ReadSync(ZclAttribute attribute) { // Log.Debug("readSync request: {Attribute}", attribute); CommandResult result; try { // TODO: Consider removing the call to .Result and use async/await all the way. (GodeGenerator and calls must be adjusted) result = Read(attribute).Result; } catch (TaskCanceledException e) // TODO: Check if this is the right exception to catch here { // Log.Debug("readSync interrupted"); return(null); } catch (Exception e) { // Log.Debug("readSync exception ", e); return(null); } if (!result.IsSuccess()) { return(null); } ReadAttributesResponse response = result.GetResponse <ReadAttributesResponse>(); if (response.Records != null && response.Records[0].Status == ZclStatus.SUCCESS) { ReadAttributeStatusRecord attributeRecord = response.Records[0]; return(_normalizer.NormalizeZclData(attribute.ZclDataType, attributeRecord.AttributeValue)); } return(null); }
/// <summary> /// Configures the reporting for the specified attribute ID for discrete attributes. /// /// minInterval: /// The minimum reporting interval field is 16 bits in length and shall contain the /// minimum interval, in seconds, between issuing reports of the specified attribute. /// If minInterval is set to 0x0000, then there is no minimum limit, unless one is /// imposed by the specification of the cluster using this reporting mechanism or by /// the applicable profile. /// /// maxInterval: /// The maximum reporting interval field is 16 bits in length and shall contain the /// maximum interval, in seconds, between issuing reports of the specified attribute. /// If maxInterval is set to 0xffff, then the device shall not issue reports for the specified /// attribute, and the configuration information for that attribute need not be /// maintained. /// /// <param name="attribute">the <see cref="ZclAttribute"> to configure reporting</param> /// <param name="minInterval">the minimum reporting interval</param> /// <param name="maxInterval">the maximum reporting interval</param> /// <returns>command Task CommandResult</returns> /// </summary> public Task <CommandResult> SetReporting(ZclAttribute attribute, ushort minInterval, ushort maxInterval) { return(SetReporting(attribute, minInterval, maxInterval, null)); }
/// <summary> /// Write an attribute /// /// <param name="attribute">the ZclAttribute to write</param> /// <param name="value">the value to set (as Object)</param> /// <returns>command Task CommandResult</returns> /// </summary> public Task <CommandResult> Write(ZclAttribute attribute, object value) { return(Write(attribute.Id, attribute.ZclDataType, value)); }
/// <summary> /// Read an attribute /// /// <param name="attribute">the <see cref="ZclAttribute"> to read</param> /// <returns>command Task</returns> /// </summary> public Task <CommandResult> Read(ZclAttribute attribute) { return(Read(attribute.Id)); }