Search in sources :

Example 1 with ZigBeeCommand

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

the class ZclClusterTest method unbind.

@Test
public void unbind() {
    createNetworkManager();
    ZigBeeNode node = new ZigBeeNode(networkManager, new IeeeAddress());
    node.setNetworkAddress(1234);
    ZigBeeEndpoint device = new ZigBeeEndpoint(networkManager, node, 5);
    ZclCluster cluster = new ZclOnOffCluster(networkManager, device);
    cluster.unbind(new IeeeAddress("1234567890ABCDEF"), 11);
    assertEquals(1, commandCapture.getAllValues().size());
    ZigBeeCommand command = commandCapture.getValue();
    assertNotNull(command);
    System.out.println(command);
    assertTrue(command instanceof UnbindRequest);
    UnbindRequest unbindCommand = (UnbindRequest) command;
    assertEquals(new ZigBeeEndpointAddress(1234, 0), unbindCommand.getDestinationAddress());
    assertEquals(new IeeeAddress("1234567890ABCDEF"), unbindCommand.getDstAddress());
    assertEquals(Integer.valueOf(5), unbindCommand.getSrcEndpoint());
    assertEquals(Integer.valueOf(11), unbindCommand.getDstEndpoint());
    assertEquals(Integer.valueOf(3), unbindCommand.getDstAddrMode());
    assertEquals(Integer.valueOf(0x0022), unbindCommand.getClusterId());
    assertEquals(Integer.valueOf(6), unbindCommand.getBindCluster());
}
Also used : ZclOnOffCluster(com.zsmartsystems.zigbee.zcl.clusters.ZclOnOffCluster) ZigBeeCommand(com.zsmartsystems.zigbee.ZigBeeCommand) ZigBeeEndpointAddress(com.zsmartsystems.zigbee.ZigBeeEndpointAddress) ZigBeeNode(com.zsmartsystems.zigbee.ZigBeeNode) ZigBeeEndpoint(com.zsmartsystems.zigbee.ZigBeeEndpoint) IeeeAddress(com.zsmartsystems.zigbee.IeeeAddress) UnbindRequest(com.zsmartsystems.zigbee.zdo.command.UnbindRequest) Test(org.junit.Test)

Example 2 with ZigBeeCommand

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

the class ZclClusterTest method getReporting.

@Test
public void getReporting() {
    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.getReporting(attribute);
    assertEquals(1, commandCapture.getAllValues().size());
    ZigBeeCommand command = commandCapture.getValue();
    assertNotNull(command);
    System.out.println(command);
    assertTrue(command instanceof ReadReportingConfigurationCommand);
    ReadReportingConfigurationCommand cfgCommand = (ReadReportingConfigurationCommand) command;
    assertEquals(1, cfgCommand.getRecords().size());
    AttributeRecord 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) AttributeRecord(com.zsmartsystems.zigbee.zcl.field.AttributeRecord) ZigBeeNode(com.zsmartsystems.zigbee.ZigBeeNode) ZigBeeEndpoint(com.zsmartsystems.zigbee.ZigBeeEndpoint) IeeeAddress(com.zsmartsystems.zigbee.IeeeAddress) ReadReportingConfigurationCommand(com.zsmartsystems.zigbee.zcl.clusters.general.ReadReportingConfigurationCommand) Test(org.junit.Test)

Example 3 with ZigBeeCommand

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

the class ZigBeeNetworkDiscovererTest method setupTest.

@Before
public void setupTest() {
    networkManager = Mockito.mock(ZigBeeNetworkManager.class);
    nodeCapture = ArgumentCaptor.forClass(ZigBeeNode.class);
    // commandCapture = ArgumentCaptor.forClass(ZigBeeCommand.class);
    // matcherCapture = ArgumentCaptor.forClass(CommandResponseMatcher.class);
    // Mockito.when(networkManager.unicast(commandCapture.capture(), matcherCapture.capture())).thenReturn(null);
    Mockito.doAnswer(new Answer<Future<CommandResult>>() {

        @Override
        public Future<CommandResult> answer(InvocationOnMock invocation) {
            ZigBeeCommand command = (ZigBeeCommand) invocation.getArguments()[0];
            CommandResultFuture commandFuture = new CommandResultFuture(networkManager);
            CommandResult result = new CommandResult(responses.get(command.getClusterId()));
            commandFuture.set(result);
            return commandFuture;
        }
    }).when(networkManager).unicast(org.mockito.Matchers.any(ZigBeeCommand.class), org.mockito.Matchers.any(ZigBeeTransactionMatcher.class));
    Mockito.doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) {
            Runnable runnable = (Runnable) invocation.getArguments()[0];
            new Thread(runnable).start();
            return null;
        }
    }).when(networkManager).executeTask(org.mockito.Matchers.any(Runnable.class));
}
Also used : ZigBeeNode(com.zsmartsystems.zigbee.ZigBeeNode) ZigBeeNetworkManager(com.zsmartsystems.zigbee.ZigBeeNetworkManager) CommandResult(com.zsmartsystems.zigbee.CommandResult) CommandResultFuture(com.zsmartsystems.zigbee.CommandResultFuture) ZigBeeCommand(com.zsmartsystems.zigbee.ZigBeeCommand) InvocationOnMock(org.mockito.invocation.InvocationOnMock) CommandResultFuture(com.zsmartsystems.zigbee.CommandResultFuture) Future(java.util.concurrent.Future) ZigBeeTransactionMatcher(com.zsmartsystems.zigbee.ZigBeeTransactionMatcher) Before(org.junit.Before)

Example 4 with ZigBeeCommand

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

the class ZigBeeOtaServerTest method testNotify.

@Test
public void testNotify() {
    ArgumentCaptor<ZigBeeCommand> mockedCommandCaptor = ArgumentCaptor.forClass(ZigBeeCommand.class);
    NodeDescriptor nodeDescriptor = new NodeDescriptor();
    IeeeAddress ieeeAddress = new IeeeAddress("1234567890ABCDEF");
    ZigBeeEndpointAddress networkAddress = new ZigBeeEndpointAddress(1234, 56);
    ZigBeeNetworkManager mockedNetworkManager = Mockito.mock(ZigBeeNetworkManager.class);
    ZigBeeNode node = new ZigBeeNode(mockedNetworkManager, ieeeAddress);
    node.setNetworkAddress(networkAddress.getAddress());
    node.setNodeDescriptor(nodeDescriptor);
    ZigBeeEndpoint endpoint = new ZigBeeEndpoint(mockedNetworkManager, node, networkAddress.getEndpoint());
    // device.setIeeeAddress(ieeeAddress);
    List<Integer> outClusters = new ArrayList<Integer>();
    outClusters.add(ZclOtaUpgradeCluster.CLUSTER_ID);
    endpoint.setOutputClusterIds(outClusters);
    ZigBeeOtaStatusCallback mockedCallback = Mockito.mock(ZigBeeOtaStatusCallback.class);
    otaStatusCapture = new ArrayList<ZigBeeOtaServerStatus>();
    Set<ZigBeeEndpoint> devices = new HashSet<ZigBeeEndpoint>();
    devices.add(endpoint);
    Mockito.when(mockedNetworkManager.getNode((IeeeAddress) Matchers.anyObject())).thenReturn(node);
    // Mockito.when(mockedNetworkManager.getDevice((ZigBeeAddress) Matchers.anyObject())).thenReturn(endpoint);
    // Mockito.when(mockedNetworkManager.getNodeDevices((IeeeAddress) Matchers.anyObject())).thenReturn(devices);
    // ZigBeeTransportTransmit mockedTransport = Mockito.mock(ZigBeeTransportTransmit.class);
    // ArgumentCaptor<ZigBeeApsFrame> mockedApsFrameListener = ArgumentCaptor.forClass(ZigBeeApsFrame.class);
    // try {
    // Mockito.doNothing().when(mockedTransport).sendCommand(mockedApsFrameListener.capture());
    // } catch (ZigBeeException e) {
    // e.printStackTrace();
    // }
    Mockito.doAnswer(new Answer<Integer>() {

        @Override
        public Integer answer(InvocationOnMock invocation) {
            return 0;
        }
    }).when(mockedNetworkManager).sendCommand(mockedCommandCaptor.capture());
    Mockito.doAnswer(new Answer<Future<CommandResult>>() {

        @Override
        public Future<CommandResult> answer(InvocationOnMock invocation) {
            return null;
        }
    }).when(mockedNetworkManager).unicast(mockedCommandCaptor.capture(), (ZigBeeTransactionMatcher) Matchers.anyObject());
    ZclOtaUpgradeCluster cluster = new ZclOtaUpgradeCluster(mockedNetworkManager, endpoint);
    ZigBeeOtaServer server = new ZigBeeOtaServer();
    assertTrue(server.appStartup(cluster));
    server.addListener(this);
    ZigBeeOtaFile otaFile = Mockito.mock(ZigBeeOtaFile.class);
    // Set the firmware and send notification
    server.setFirmware(otaFile);
    assertEquals(1, mockedCommandCaptor.getAllValues().size());
    org.awaitility.Awaitility.await().until(otaListenerUpdated(), org.hamcrest.Matchers.equalTo(1));
    assertEquals(1, otaStatusCapture.size());
    ZigBeeOtaServerStatus status = otaStatusCapture.get(0);
    assertEquals(ZigBeeOtaServerStatus.OTA_WAITING, status);
    ZigBeeCommand command = mockedCommandCaptor.getValue();
    assertEquals(Integer.valueOf(0x19), command.getClusterId());
    assertTrue(command instanceof ImageNotifyCommand);
    ImageNotifyCommand notifyCommand = (ImageNotifyCommand) command;
    assertEquals(new ZigBeeEndpointAddress(1234, 56), notifyCommand.getDestinationAddress());
    assertTrue(notifyCommand.getQueryJitter() >= 1 && notifyCommand.getQueryJitter() <= 100);
}
Also used : ZigBeeOtaFile(com.zsmartsystems.zigbee.app.otaserver.ZigBeeOtaFile) NodeDescriptor(com.zsmartsystems.zigbee.zdo.field.NodeDescriptor) ArrayList(java.util.ArrayList) ZigBeeNetworkManager(com.zsmartsystems.zigbee.ZigBeeNetworkManager) ZigBeeOtaStatusCallback(com.zsmartsystems.zigbee.app.otaserver.ZigBeeOtaStatusCallback) ZigBeeCommand(com.zsmartsystems.zigbee.ZigBeeCommand) ZigBeeEndpointAddress(com.zsmartsystems.zigbee.ZigBeeEndpointAddress) ZigBeeOtaServerStatus(com.zsmartsystems.zigbee.app.otaserver.ZigBeeOtaServerStatus) ZigBeeEndpoint(com.zsmartsystems.zigbee.ZigBeeEndpoint) HashSet(java.util.HashSet) ZigBeeOtaServer(com.zsmartsystems.zigbee.app.otaserver.ZigBeeOtaServer) ZigBeeNode(com.zsmartsystems.zigbee.ZigBeeNode) ZclOtaUpgradeCluster(com.zsmartsystems.zigbee.zcl.clusters.ZclOtaUpgradeCluster) IeeeAddress(com.zsmartsystems.zigbee.IeeeAddress) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Future(java.util.concurrent.Future) ImageNotifyCommand(com.zsmartsystems.zigbee.zcl.clusters.otaupgrade.ImageNotifyCommand) Test(org.junit.Test)

Example 5 with ZigBeeCommand

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

the class ZclClusterTest method bind.

@Test
public void bind() {
    createNetworkManager();
    ZigBeeNode node = new ZigBeeNode(networkManager, new IeeeAddress());
    node.setNetworkAddress(1234);
    ZigBeeEndpoint device = new ZigBeeEndpoint(networkManager, node, 5);
    ZclCluster cluster = new ZclOnOffCluster(networkManager, device);
    cluster.bind(new IeeeAddress("1234567890ABCDEF"), 11);
    assertEquals(1, commandCapture.getAllValues().size());
    ZigBeeCommand command = commandCapture.getValue();
    assertNotNull(command);
    System.out.println(command);
    assertTrue(command instanceof BindRequest);
    BindRequest bindCommand = (BindRequest) command;
    assertEquals(new ZigBeeEndpointAddress(1234, 0), bindCommand.getDestinationAddress());
    assertEquals(new IeeeAddress("1234567890ABCDEF"), bindCommand.getDstAddress());
    assertEquals(Integer.valueOf(5), bindCommand.getSrcEndpoint());
    assertEquals(Integer.valueOf(11), bindCommand.getDstEndpoint());
    assertEquals(Integer.valueOf(3), bindCommand.getDstAddrMode());
    assertEquals(Integer.valueOf(0x0021), bindCommand.getClusterId());
    assertEquals(Integer.valueOf(6), bindCommand.getBindCluster());
}
Also used : ZclOnOffCluster(com.zsmartsystems.zigbee.zcl.clusters.ZclOnOffCluster) ZigBeeCommand(com.zsmartsystems.zigbee.ZigBeeCommand) ZigBeeEndpointAddress(com.zsmartsystems.zigbee.ZigBeeEndpointAddress) BindRequest(com.zsmartsystems.zigbee.zdo.command.BindRequest) ZigBeeNode(com.zsmartsystems.zigbee.ZigBeeNode) ZigBeeEndpoint(com.zsmartsystems.zigbee.ZigBeeEndpoint) IeeeAddress(com.zsmartsystems.zigbee.IeeeAddress) Test(org.junit.Test)

Aggregations

ZigBeeCommand (com.zsmartsystems.zigbee.ZigBeeCommand)6 ZigBeeNode (com.zsmartsystems.zigbee.ZigBeeNode)6 IeeeAddress (com.zsmartsystems.zigbee.IeeeAddress)5 ZigBeeEndpoint (com.zsmartsystems.zigbee.ZigBeeEndpoint)5 Test (org.junit.Test)5 ZclOnOffCluster (com.zsmartsystems.zigbee.zcl.clusters.ZclOnOffCluster)4 ZigBeeEndpointAddress (com.zsmartsystems.zigbee.ZigBeeEndpointAddress)3 ZigBeeNetworkManager (com.zsmartsystems.zigbee.ZigBeeNetworkManager)2 Future (java.util.concurrent.Future)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 CommandResult (com.zsmartsystems.zigbee.CommandResult)1 CommandResultFuture (com.zsmartsystems.zigbee.CommandResultFuture)1 ZigBeeTransactionMatcher (com.zsmartsystems.zigbee.ZigBeeTransactionMatcher)1 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 ZclOtaUpgradeCluster (com.zsmartsystems.zigbee.zcl.clusters.ZclOtaUpgradeCluster)1 ConfigureReportingCommand (com.zsmartsystems.zigbee.zcl.clusters.general.ConfigureReportingCommand)1 ReadReportingConfigurationCommand (com.zsmartsystems.zigbee.zcl.clusters.general.ReadReportingConfigurationCommand)1