Search in sources :

Example 1 with AttributeReport

use of com.zsmartsystems.zigbee.zcl.field.AttributeReport in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZclCluster method handleAttributeReport.

/**
 * Processes a list of attribute reports for this cluster
 *
 * @param reports {@List} of {@link AttributeReport}
 */
public void handleAttributeReport(List<AttributeReport> reports) {
    for (AttributeReport report : reports) {
        ZclAttribute attribute = attributes.get(report.getAttributeIdentifier());
        if (attribute == null) {
            logger.debug("{}: Unknown attribute {} in cluster {}", zigbeeEndpoint.getEndpointAddress(), report.getAttributeIdentifier(), clusterId);
        } else {
            attribute.updateValue(normalizer.normalizeZclData(attribute.getDataType(), report.getAttributeValue()));
            notifyAttributeListener(attribute);
        }
    }
}
Also used : AttributeReport(com.zsmartsystems.zigbee.zcl.field.AttributeReport)

Example 2 with AttributeReport

use of com.zsmartsystems.zigbee.zcl.field.AttributeReport in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZclClusterTest method handleAttributeReport.

@Test
public void handleAttributeReport() {
    createNetworkManager();
    ZigBeeNode node = new ZigBeeNode(networkManager, new IeeeAddress());
    node.setNetworkAddress(1234);
    ZigBeeEndpoint device = new ZigBeeEndpoint(networkManager, node, 5);
    ZclCluster cluster = new ZclOnOffCluster(networkManager, device);
    ZclAttributeListener listenerMock = Mockito.mock(ZclAttributeListener.class);
    ArgumentCaptor<ZclAttribute> attributeCapture = ArgumentCaptor.forClass(ZclAttribute.class);
    cluster.addAttributeListener(listenerMock);
    List<AttributeReport> attributeList = new ArrayList<AttributeReport>();
    AttributeReport report;
    report = new AttributeReport();
    report.setAttributeDataType(ZclDataType.SIGNED_8_BIT_INTEGER);
    report.setAttributeIdentifier(0);
    report.setAttributeValue(Integer.valueOf(1));
    System.out.println(report);
    attributeList.add(report);
    cluster.handleAttributeReport(attributeList);
    ZclAttribute attribute = cluster.getAttribute(0);
    assertTrue(attribute.getLastValue() instanceof Boolean);
    Mockito.verify(listenerMock, Mockito.timeout(1000).times(1)).attributeUpdated(attributeCapture.capture());
    attribute = attributeCapture.getValue();
    assertTrue(attribute.getLastValue() instanceof Boolean);
    assertEquals(ZclDataType.BOOLEAN, attribute.getDataType());
    assertEquals(0, attribute.getId());
    assertEquals(true, attribute.getLastValue());
}
Also used : AttributeReport(com.zsmartsystems.zigbee.zcl.field.AttributeReport) ZclOnOffCluster(com.zsmartsystems.zigbee.zcl.clusters.ZclOnOffCluster) ArrayList(java.util.ArrayList) ZigBeeNode(com.zsmartsystems.zigbee.ZigBeeNode) ZigBeeEndpoint(com.zsmartsystems.zigbee.ZigBeeEndpoint) IeeeAddress(com.zsmartsystems.zigbee.IeeeAddress) Test(org.junit.Test)

Aggregations

AttributeReport (com.zsmartsystems.zigbee.zcl.field.AttributeReport)2 IeeeAddress (com.zsmartsystems.zigbee.IeeeAddress)1 ZigBeeEndpoint (com.zsmartsystems.zigbee.ZigBeeEndpoint)1 ZigBeeNode (com.zsmartsystems.zigbee.ZigBeeNode)1 ZclOnOffCluster (com.zsmartsystems.zigbee.zcl.clusters.ZclOnOffCluster)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1