Search in sources :

Example 21 with ZigBeeEndpoint

use of com.zsmartsystems.zigbee.ZigBeeEndpoint 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 22 with ZigBeeEndpoint

use of com.zsmartsystems.zigbee.ZigBeeEndpoint in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZclClusterTest method getClusterName.

@Test
public void getClusterName() {
    createNetworkManager();
    ZigBeeNode node = new ZigBeeNode(networkManager, new IeeeAddress());
    node.setNetworkAddress(1234);
    ZigBeeEndpoint device = new ZigBeeEndpoint(networkManager, node, 5);
    ZclCluster cluster = new ZclLevelControlCluster(networkManager, device);
    assertEquals("Level Control", cluster.getClusterName());
}
Also used : ZigBeeNode(com.zsmartsystems.zigbee.ZigBeeNode) ZclLevelControlCluster(com.zsmartsystems.zigbee.zcl.clusters.ZclLevelControlCluster) ZigBeeEndpoint(com.zsmartsystems.zigbee.ZigBeeEndpoint) IeeeAddress(com.zsmartsystems.zigbee.IeeeAddress) Test(org.junit.Test)

Example 23 with ZigBeeEndpoint

use of com.zsmartsystems.zigbee.ZigBeeEndpoint 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 24 with ZigBeeEndpoint

use of com.zsmartsystems.zigbee.ZigBeeEndpoint 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)

Example 25 with ZigBeeEndpoint

use of com.zsmartsystems.zigbee.ZigBeeEndpoint in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZigBeeNodeServiceDiscoverer method getSimpleDescriptor.

/**
 * Get the simple descriptor for an endpoint and create the {@link ZigBeeEndpoint}
 *
 * @param endpointId the endpoint id to request
 * @return the newly created {@link ZigBeeEndpoint} for the endpoint, or null on error
 * @throws ExecutionException
 * @throws InterruptedException
 */
private ZigBeeEndpoint getSimpleDescriptor(final int endpointId) throws InterruptedException, ExecutionException {
    final SimpleDescriptorRequest simpleDescriptorRequest = new SimpleDescriptorRequest();
    simpleDescriptorRequest.setDestinationAddress(new ZigBeeEndpointAddress(node.getNetworkAddress()));
    simpleDescriptorRequest.setNwkAddrOfInterest(node.getNetworkAddress());
    simpleDescriptorRequest.setEndpoint(endpointId);
    CommandResult response = networkManager.unicast(simpleDescriptorRequest, simpleDescriptorRequest).get();
    final SimpleDescriptorResponse simpleDescriptorResponse = (SimpleDescriptorResponse) response.getResponse();
    logger.debug("{}: Node SVC Discovery SimpleDescriptorResponse returned {}", node.getIeeeAddress(), simpleDescriptorResponse);
    if (simpleDescriptorResponse == null) {
        return null;
    }
    if (simpleDescriptorResponse.getStatus() == ZdoStatus.SUCCESS) {
        ZigBeeEndpoint endpoint = new ZigBeeEndpoint(networkManager, node, endpointId);
        SimpleDescriptor simpleDescriptor = simpleDescriptorResponse.getSimpleDescriptor();
        endpoint.setProfileId(simpleDescriptor.getProfileId());
        endpoint.setDeviceId(simpleDescriptor.getDeviceId());
        endpoint.setDeviceVersion(simpleDescriptor.getDeviceVersion());
        endpoint.setInputClusterIds(simpleDescriptor.getInputClusterList());
        endpoint.setOutputClusterIds(simpleDescriptor.getOutputClusterList());
        return endpoint;
    }
    return null;
}
Also used : SimpleDescriptorResponse(com.zsmartsystems.zigbee.zdo.command.SimpleDescriptorResponse) ZigBeeEndpointAddress(com.zsmartsystems.zigbee.ZigBeeEndpointAddress) SimpleDescriptorRequest(com.zsmartsystems.zigbee.zdo.command.SimpleDescriptorRequest) ZigBeeEndpoint(com.zsmartsystems.zigbee.ZigBeeEndpoint) CommandResult(com.zsmartsystems.zigbee.CommandResult) SimpleDescriptor(com.zsmartsystems.zigbee.zdo.field.SimpleDescriptor)

Aggregations

ZigBeeEndpoint (com.zsmartsystems.zigbee.ZigBeeEndpoint)25 IeeeAddress (com.zsmartsystems.zigbee.IeeeAddress)12 ZigBeeNode (com.zsmartsystems.zigbee.ZigBeeNode)12 Test (org.junit.Test)10 CommandResult (com.zsmartsystems.zigbee.CommandResult)9 ZclCluster (com.zsmartsystems.zigbee.zcl.ZclCluster)8 ZclOnOffCluster (com.zsmartsystems.zigbee.zcl.clusters.ZclOnOffCluster)8 ZigBeeEndpointAddress (com.zsmartsystems.zigbee.ZigBeeEndpointAddress)6 ZclAttribute (com.zsmartsystems.zigbee.zcl.ZclAttribute)6 ZigBeeCommand (com.zsmartsystems.zigbee.ZigBeeCommand)5 ZclStatus (com.zsmartsystems.zigbee.zcl.ZclStatus)5 ArrayList (java.util.ArrayList)4 ZigBeeNetworkManager (com.zsmartsystems.zigbee.ZigBeeNetworkManager)2 ConfigureReportingResponse (com.zsmartsystems.zigbee.zcl.clusters.general.ConfigureReportingResponse)2 ReadAttributesResponse (com.zsmartsystems.zigbee.zcl.clusters.general.ReadAttributesResponse)2 HashSet (java.util.HashSet)2 ZigBeeOtaFile (com.zsmartsystems.zigbee.app.otaserver.ZigBeeOtaFile)1 ZigBeeOtaServer (com.zsmartsystems.zigbee.app.otaserver.ZigBeeOtaServer)1 ZigBeeOtaServerStatus (com.zsmartsystems.zigbee.app.otaserver.ZigBeeOtaServerStatus)1 ZigBeeOtaStatusCallback (com.zsmartsystems.zigbee.app.otaserver.ZigBeeOtaStatusCallback)1