Search in sources :

Example 6 with ZclOnOffCluster

use of com.zsmartsystems.zigbee.zcl.clusters.ZclOnOffCluster 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)

Example 7 with ZclOnOffCluster

use of com.zsmartsystems.zigbee.zcl.clusters.ZclOnOffCluster in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZclClusterTest method getClusterId.

@Test
public void getClusterId() {
    createNetworkManager();
    ZigBeeNode node = new ZigBeeNode(networkManager, new IeeeAddress());
    node.setNetworkAddress(1234);
    ZigBeeEndpoint device = new ZigBeeEndpoint(networkManager, node, 5);
    ZclCluster cluster = new ZclOnOffCluster(networkManager, device);
    assertEquals(Integer.valueOf(6), cluster.getClusterId());
}
Also used : ZclOnOffCluster(com.zsmartsystems.zigbee.zcl.clusters.ZclOnOffCluster) ZigBeeNode(com.zsmartsystems.zigbee.ZigBeeNode) ZigBeeEndpoint(com.zsmartsystems.zigbee.ZigBeeEndpoint) IeeeAddress(com.zsmartsystems.zigbee.IeeeAddress) Test(org.junit.Test)

Example 8 with ZclOnOffCluster

use of com.zsmartsystems.zigbee.zcl.clusters.ZclOnOffCluster in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZclClusterTest method setReporting.

@Test
public void setReporting() {
    createNetworkManager();
    ZigBeeNode node = new ZigBeeNode(networkManager, new IeeeAddress());
    node.setNetworkAddress(1234);
    ZigBeeEndpoint device = new ZigBeeEndpoint(networkManager, node, 5);
    ZclCluster cluster = new ZclOnOffCluster(networkManager, device);
    ZclAttribute attribute = cluster.getAttribute(0);
    cluster.setReporting(attribute, 22, 33);
    assertEquals(1, commandCapture.getAllValues().size());
    ZigBeeCommand command = commandCapture.getValue();
    assertNotNull(command);
    System.out.println(command);
    assertTrue(command instanceof ConfigureReportingCommand);
    ConfigureReportingCommand cfgCommand = (ConfigureReportingCommand) command;
    assertEquals(1, cfgCommand.getRecords().size());
    AttributeReportingConfigurationRecord record = cfgCommand.getRecords().get(0);
    assertEquals(0, record.getAttributeIdentifier());
    assertEquals(0, record.getDirection());
}
Also used : ZclOnOffCluster(com.zsmartsystems.zigbee.zcl.clusters.ZclOnOffCluster) ZigBeeCommand(com.zsmartsystems.zigbee.ZigBeeCommand) AttributeReportingConfigurationRecord(com.zsmartsystems.zigbee.zcl.field.AttributeReportingConfigurationRecord) ZigBeeNode(com.zsmartsystems.zigbee.ZigBeeNode) ConfigureReportingCommand(com.zsmartsystems.zigbee.zcl.clusters.general.ConfigureReportingCommand) ZigBeeEndpoint(com.zsmartsystems.zigbee.ZigBeeEndpoint) IeeeAddress(com.zsmartsystems.zigbee.IeeeAddress) Test(org.junit.Test)

Aggregations

ZigBeeEndpoint (com.zsmartsystems.zigbee.ZigBeeEndpoint)8 ZclOnOffCluster (com.zsmartsystems.zigbee.zcl.clusters.ZclOnOffCluster)8 IeeeAddress (com.zsmartsystems.zigbee.IeeeAddress)7 ZigBeeNode (com.zsmartsystems.zigbee.ZigBeeNode)7 Test (org.junit.Test)7 ZigBeeCommand (com.zsmartsystems.zigbee.ZigBeeCommand)4 ZigBeeEndpointAddress (com.zsmartsystems.zigbee.ZigBeeEndpointAddress)3 ConfigureReportingCommand (com.zsmartsystems.zigbee.zcl.clusters.general.ConfigureReportingCommand)1 ReadReportingConfigurationCommand (com.zsmartsystems.zigbee.zcl.clusters.general.ReadReportingConfigurationCommand)1 AttributeRecord (com.zsmartsystems.zigbee.zcl.field.AttributeRecord)1 AttributeReport (com.zsmartsystems.zigbee.zcl.field.AttributeReport)1 AttributeReportingConfigurationRecord (com.zsmartsystems.zigbee.zcl.field.AttributeReportingConfigurationRecord)1 BindRequest (com.zsmartsystems.zigbee.zdo.command.BindRequest)1 UnbindRequest (com.zsmartsystems.zigbee.zdo.command.UnbindRequest)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1