@Test public void nodeStatusUpdate() throws Exception { TestUtilities.outputTestHeader(); ZigBeeNetworkManager manager = mockZigBeeNetworkManager(); ZigBeeNode node = Mockito.mock(ZigBeeNode.class); Mockito.when(node.getIeeeAddress()).thenReturn(new IeeeAddress("1234567890ABCDEF")); manager.updateNode(node); ZigBeeAnnounceListener announceListener = Mockito.mock(ZigBeeAnnounceListener.class); manager.addAnnounceListener(announceListener); assertEquals(1, ((Collection<ZigBeeAnnounceListener>) TestUtilities.getField(ZigBeeNetworkManager.class, manager, "announceListeners")).size()); manager.addAnnounceListener(announceListener); assertEquals(1, ((Collection<ZigBeeAnnounceListener>) TestUtilities.getField(ZigBeeNetworkManager.class, manager, "announceListeners")).size()); manager.nodeStatusUpdate(ZigBeeNodeStatus.DEVICE_LEFT, 1234, new IeeeAddress("123456789ABCDEF0")); Mockito.verify(node, Mockito.times(0)).setNodeState(ArgumentMatchers.any(ZigBeeNodeState.class)); Mockito.verify(announceListener, Mockito.timeout(TIMEOUT).times(1)).deviceStatusUpdate( ArgumentMatchers.any(ZigBeeNodeStatus.class), ArgumentMatchers.any(Integer.class), ArgumentMatchers.any(IeeeAddress.class)); manager.nodeStatusUpdate(ZigBeeNodeStatus.DEVICE_LEFT, 1234, new IeeeAddress("1234567890ABCDEF")); Mockito.verify(node, Mockito.times(1)).setNodeState(ZigBeeNodeState.OFFLINE); Mockito.verify(announceListener, Mockito.timeout(TIMEOUT).times(2)).deviceStatusUpdate( ArgumentMatchers.any(ZigBeeNodeStatus.class), ArgumentMatchers.any(Integer.class), ArgumentMatchers.any(IeeeAddress.class)); manager.removeAnnounceListener(announceListener); }
@Override public void nodeStatusUpdate(final ZigBeeNodeStatus deviceStatus, final Integer networkAddress, final IeeeAddress ieeeAddress) { logger.debug("{}: nodeStatusUpdate - node status is {}, network address is {}.", ieeeAddress, deviceStatus, String.format("%04X", networkAddress)); switch (deviceStatus) { case DEVICE_LEFT: ZigBeeNode node = getNode(ieeeAddress); if (node == null) { node = getNode(networkAddress); } if (node == null) { logger.debug("{}: Node has left, but wasn't found in the network.", networkAddress); } else { node.setNodeState(ZigBeeNodeState.OFFLINE); updateNode(node); } break; case UNSECURED_JOIN: break; case SECURED_REJOIN: case UNSECURED_REJOIN: break; default: break; } for (final ZigBeeAnnounceListener announceListener : announceListeners) { notificationService.execute(new Runnable() { @Override public void run() { announceListener.deviceStatusUpdate(deviceStatus, networkAddress, ieeeAddress); } }); } }
ZigBeeNetworkManager implements ZigBeeTransportReceive { @Override public void nodeStatusUpdate(final ZigBeeNodeStatus deviceStatus, final Integer networkAddress, final IeeeAddress ieeeAddress) { logger.debug("{}: nodeStatusUpdate - node status is {}, network address is {}.", ieeeAddress, deviceStatus, String.format("%04X", networkAddress)); switch (deviceStatus) { case DEVICE_LEFT: ZigBeeNode node = getNode(ieeeAddress); if (node == null) { node = getNode(networkAddress); } if (node == null) { logger.debug("{}: Node has left, but wasn't found in the network.", networkAddress); } else { node.setNodeState(ZigBeeNodeState.OFFLINE); updateNode(node); } break; case UNSECURED_JOIN: break; case SECURED_REJOIN: case UNSECURED_REJOIN: break; default: break; } for (final ZigBeeAnnounceListener announceListener : announceListeners) { notificationService.execute(new Runnable() { @Override public void run() { announceListener.deviceStatusUpdate(deviceStatus, networkAddress, ieeeAddress); } }); } } }
ZigBeeNetworkManager implements ZigBeeTransportReceive { @Override public void nodeStatusUpdate(final ZigBeeNodeStatus deviceStatus, final Integer networkAddress, final IeeeAddress ieeeAddress) { logger.debug("{}: nodeStatusUpdate - node status is {}, network address is {}.", ieeeAddress, deviceStatus, String.format("%04X", networkAddress)); switch (deviceStatus) { case DEVICE_LEFT: ZigBeeNode node = getNode(ieeeAddress); if (node == null) { node = getNode(networkAddress); } if (node == null) { logger.debug("{}: Node has left, but wasn't found in the network.", networkAddress); } else { node.setNodeState(ZigBeeNodeState.OFFLINE); updateNode(node); } break; case UNSECURED_JOIN: break; case SECURED_REJOIN: case UNSECURED_REJOIN: break; default: break; } for (final ZigBeeAnnounceListener announceListener : announceListeners) { notificationService.execute(new Runnable() { @Override public void run() { announceListener.deviceStatusUpdate(deviceStatus, networkAddress, ieeeAddress); } }); } } ZigBeeNetworkManager(final ZigBeeTransportTransmit transport); }
ZigBeeNetworkManager implements ZigBeeTransportReceive { @Override public void nodeStatusUpdate(final ZigBeeNodeStatus deviceStatus, final Integer networkAddress, final IeeeAddress ieeeAddress) { logger.debug("{}: nodeStatusUpdate - node status is {}, network address is {}.", ieeeAddress, deviceStatus, String.format("%04X", networkAddress)); switch (deviceStatus) { case DEVICE_LEFT: ZigBeeNode node = getNode(ieeeAddress); if (node == null) { node = getNode(networkAddress); } if (node == null) { logger.debug("{}: Node has left, but wasn't found in the network.", networkAddress); } else { node.setNodeState(ZigBeeNodeState.OFFLINE); updateNode(node); } break; case UNSECURED_JOIN: break; case SECURED_REJOIN: case UNSECURED_REJOIN: break; default: break; } for (final ZigBeeAnnounceListener announceListener : announceListeners) { notificationService.execute(new Runnable() { @Override public void run() { announceListener.deviceStatusUpdate(deviceStatus, networkAddress, ieeeAddress); } }); } } ZigBeeNetworkManager(final ZigBeeTransportTransmit transport); void setNetworkDataStore(ZigBeeNetworkDataStore dataStore); void serializeNetworkDataStore(IeeeAddress nodeAddress); @SuppressWarnings("unchecked") void setSerializer(Class<?> serializer, Class<?> deserializer); void setLocalEndpointId(int localEndpointId); ZigBeeStatus initialize(); ZigBeeTransportTransmit getZigBeeTransport(); ZigBeeChannel getZigBeeChannel(); ZigBeeStatus setZigBeeChannel(ZigBeeChannel channel); int getZigBeePanId(); ZigBeeStatus setZigBeePanId(int panId); ExtendedPanId getZigBeeExtendedPanId(); ZigBeeStatus setZigBeeExtendedPanId(ExtendedPanId panId); ZigBeeStatus setDefaultProfileId(int defaultProfileId); ZigBeeStatus setDefaultDeviceId(int defaultDeviceId); ZigBeeStatus setZigBeeNetworkKey(final ZigBeeKey key); ZigBeeKey getZigBeeNetworkKey(); ZigBeeStatus setZigBeeLinkKey(final ZigBeeKey key); ZigBeeKey getZigBeeLinkKey(); ZigBeeStatus setZigBeeInstallKey(final ZigBeeKey key); ZigBeeStatus startup(boolean reinitialize); ZigBeeStatus reinitialize(); void shutdown(); void executeTask(Runnable runnableTask); ScheduledFuture<?> scheduleTask(Runnable runnableTask, long delay); ScheduledFuture<?> rescheduleTask(ScheduledFuture<?> futureTask, Runnable runnableTask, long delay); ScheduledFuture<?> scheduleTask(Runnable runnableTask, long initialDelay, long period); String getTransportVersionString(); boolean sendCommand(ZigBeeCommand command); void addCommandListener(ZigBeeCommandListener commandListener); void removeCommandListener(ZigBeeCommandListener commandListener); @Override void receiveCommand(final ZigBeeApsFrame incomingApsFrame); void createDefaultResponse(ZigBeeApsFrame apsFrame, ZclHeader zclHeader, ZclStatus status); void addAnnounceListener(ZigBeeAnnounceListener announceListener); void removeAnnounceListener(ZigBeeAnnounceListener announceListener); @Override void nodeStatusUpdate(final ZigBeeNodeStatus deviceStatus, final Integer networkAddress,
            final IeeeAddress ieeeAddress); void addNetworkStateListener(ZigBeeNetworkStateListener stateListener); void removeNetworkStateListener(ZigBeeNetworkStateListener stateListener); @Override synchronized void setTransportState(final ZigBeeTransportState state); ZigBeeStatus permitJoin(final int duration); ZigBeeStatus permitJoin(final ZigBeeEndpointAddress destination, final int duration); void leave(final Integer destinationAddress, final IeeeAddress leaveAddress); void leave(final Integer destinationAddress, final IeeeAddress leaveAddress, boolean forceNodeRemoval); void addGroup(final ZigBeeGroupAddress group); void updateGroup(ZigBeeGroupAddress group); ZigBeeGroupAddress getGroup(final int groupId); void removeGroup(final int groupId); List<ZigBeeGroupAddress> getGroups(); void addNetworkNodeListener(final ZigBeeNetworkNodeListener networkNodeListener); void removeNetworkNodeListener(final ZigBeeNetworkNodeListener networkNodeListener); void rediscoverNode(IeeeAddress address); Set<ZigBeeNode> getNodes(); ZigBeeNode getNode(final Integer networkAddress); ZigBeeNode getNode(final IeeeAddress ieeeAddress); void removeNode(final ZigBeeNode node); void updateNode(final ZigBeeNode node); @Deprecated void addSupportedCluster(int cluster); ZigBeeStatus addSupportedClientCluster(int cluster); ZigBeeStatus addSupportedServerCluster(int cluster); boolean isClientClusterSupported(int cluster); boolean isServerClusterSupported(int cluster); ZigBeeStatus addExtension(ZigBeeNetworkExtension extension); ZigBeeNetworkExtension getExtension(Class<T> requestedExtension); ZigBeeNetworkState getNetworkState(); IeeeAddress getLocalIeeeAddress(); Integer getLocalNwkAddress(); NotificationService getNotificationService(); void sendTransaction(ZigBeeCommand command); Future<CommandResult> sendTransaction(ZigBeeCommand command, ZigBeeTransactionMatcher responseMatcher); @Override void receiveCommandState(int msgTag, ZigBeeTransportProgressState state); }
ZigBeeNetworkManager implements ZigBeeTransportReceive { @Override public void nodeStatusUpdate(final ZigBeeNodeStatus deviceStatus, final Integer networkAddress, final IeeeAddress ieeeAddress) { logger.debug("{}: nodeStatusUpdate - node status is {}, network address is {}.", ieeeAddress, deviceStatus, String.format("%04X", networkAddress)); switch (deviceStatus) { case DEVICE_LEFT: ZigBeeNode node = getNode(ieeeAddress); if (node == null) { node = getNode(networkAddress); } if (node == null) { logger.debug("{}: Node has left, but wasn't found in the network.", networkAddress); } else { node.setNodeState(ZigBeeNodeState.OFFLINE); updateNode(node); } break; case UNSECURED_JOIN: break; case SECURED_REJOIN: case UNSECURED_REJOIN: break; default: break; } for (final ZigBeeAnnounceListener announceListener : announceListeners) { notificationService.execute(new Runnable() { @Override public void run() { announceListener.deviceStatusUpdate(deviceStatus, networkAddress, ieeeAddress); } }); } } ZigBeeNetworkManager(final ZigBeeTransportTransmit transport); void setNetworkDataStore(ZigBeeNetworkDataStore dataStore); void serializeNetworkDataStore(IeeeAddress nodeAddress); @SuppressWarnings("unchecked") void setSerializer(Class<?> serializer, Class<?> deserializer); void setLocalEndpointId(int localEndpointId); ZigBeeStatus initialize(); ZigBeeTransportTransmit getZigBeeTransport(); ZigBeeChannel getZigBeeChannel(); ZigBeeStatus setZigBeeChannel(ZigBeeChannel channel); int getZigBeePanId(); ZigBeeStatus setZigBeePanId(int panId); ExtendedPanId getZigBeeExtendedPanId(); ZigBeeStatus setZigBeeExtendedPanId(ExtendedPanId panId); ZigBeeStatus setDefaultProfileId(int defaultProfileId); ZigBeeStatus setDefaultDeviceId(int defaultDeviceId); ZigBeeStatus setZigBeeNetworkKey(final ZigBeeKey key); ZigBeeKey getZigBeeNetworkKey(); ZigBeeStatus setZigBeeLinkKey(final ZigBeeKey key); ZigBeeKey getZigBeeLinkKey(); ZigBeeStatus setZigBeeInstallKey(final ZigBeeKey key); ZigBeeStatus startup(boolean reinitialize); ZigBeeStatus reinitialize(); void shutdown(); void executeTask(Runnable runnableTask); ScheduledFuture<?> scheduleTask(Runnable runnableTask, long delay); ScheduledFuture<?> rescheduleTask(ScheduledFuture<?> futureTask, Runnable runnableTask, long delay); ScheduledFuture<?> scheduleTask(Runnable runnableTask, long initialDelay, long period); String getTransportVersionString(); boolean sendCommand(ZigBeeCommand command); void addCommandListener(ZigBeeCommandListener commandListener); void removeCommandListener(ZigBeeCommandListener commandListener); @Override void receiveCommand(final ZigBeeApsFrame incomingApsFrame); void createDefaultResponse(ZigBeeApsFrame apsFrame, ZclHeader zclHeader, ZclStatus status); void addAnnounceListener(ZigBeeAnnounceListener announceListener); void removeAnnounceListener(ZigBeeAnnounceListener announceListener); @Override void nodeStatusUpdate(final ZigBeeNodeStatus deviceStatus, final Integer networkAddress,
            final IeeeAddress ieeeAddress); void addNetworkStateListener(ZigBeeNetworkStateListener stateListener); void removeNetworkStateListener(ZigBeeNetworkStateListener stateListener); @Override synchronized void setTransportState(final ZigBeeTransportState state); ZigBeeStatus permitJoin(final int duration); ZigBeeStatus permitJoin(final ZigBeeEndpointAddress destination, final int duration); void leave(final Integer destinationAddress, final IeeeAddress leaveAddress); void leave(final Integer destinationAddress, final IeeeAddress leaveAddress, boolean forceNodeRemoval); void addGroup(final ZigBeeGroupAddress group); void updateGroup(ZigBeeGroupAddress group); ZigBeeGroupAddress getGroup(final int groupId); void removeGroup(final int groupId); List<ZigBeeGroupAddress> getGroups(); void addNetworkNodeListener(final ZigBeeNetworkNodeListener networkNodeListener); void removeNetworkNodeListener(final ZigBeeNetworkNodeListener networkNodeListener); void rediscoverNode(IeeeAddress address); Set<ZigBeeNode> getNodes(); ZigBeeNode getNode(final Integer networkAddress); ZigBeeNode getNode(final IeeeAddress ieeeAddress); void removeNode(final ZigBeeNode node); void updateNode(final ZigBeeNode node); @Deprecated void addSupportedCluster(int cluster); ZigBeeStatus addSupportedClientCluster(int cluster); ZigBeeStatus addSupportedServerCluster(int cluster); boolean isClientClusterSupported(int cluster); boolean isServerClusterSupported(int cluster); ZigBeeStatus addExtension(ZigBeeNetworkExtension extension); ZigBeeNetworkExtension getExtension(Class<T> requestedExtension); ZigBeeNetworkState getNetworkState(); IeeeAddress getLocalIeeeAddress(); Integer getLocalNwkAddress(); NotificationService getNotificationService(); void sendTransaction(ZigBeeCommand command); Future<CommandResult> sendTransaction(ZigBeeCommand command, ZigBeeTransactionMatcher responseMatcher); @Override void receiveCommandState(int msgTag, ZigBeeTransportProgressState state);  }