@Test public void handleCommand() throws Exception { createEndpoint(); ZclCluster cluster = new ZclOnOffCluster(endpoint); Set<ZclCommandListener> commandListeners = (Set<ZclCommandListener>) TestUtilities.getField(ZclCluster.class, cluster, "commandListeners"); assertEquals(0, commandListeners.size()); int tid = 123; ZclCommand command = Mockito.mock(ZclCommand.class); Mockito.when(command.getTransactionId()).thenReturn(tid); Mockito.when(command.getCommandId()).thenReturn(45); Mockito.when(command.isGenericCommand()).thenReturn(false); Mockito.when(command.isManufacturerSpecific()).thenReturn(false); Mockito.when(command.getCommandDirection()).thenReturn(ZclCommandDirection.CLIENT_TO_SERVER); ZclCommandListener listenerMock = Mockito.mock(ZclCommandListener.class); cluster.addCommandListener(listenerMock); assertEquals(1, commandListeners.size()); cluster.addCommandListener(listenerMock); assertEquals(1, commandListeners.size()); cluster.handleCommand(command); Mockito.verify(endpoint, Mockito.timeout(TIMEOUT).times(1)).sendTransaction(commandCapture.capture()); ZigBeeCommand response = commandCapture.getValue(); assertTrue(response instanceof DefaultResponse); System.out.println(response); DefaultResponse defaultResponse = (DefaultResponse) response; assertEquals(Integer.valueOf(45), defaultResponse.getCommandIdentifier()); assertEquals(ZclStatus.UNSUP_CLUSTER_COMMAND, defaultResponse.getStatusCode()); assertEquals(Integer.valueOf(tid), defaultResponse.getTransactionId()); Mockito.verify(listenerMock, Mockito.timeout(TIMEOUT).times(1)).commandReceived(command); Mockito.when(command.getTransactionId()).thenReturn(++tid); Mockito.when(command.isGenericCommand()).thenReturn(true); cluster.handleCommand(command); Mockito.verify(endpoint, Mockito.timeout(TIMEOUT).times(2)).sendTransaction(commandCapture.capture()); response = commandCapture.getValue(); assertTrue(response instanceof DefaultResponse); System.out.println(response); defaultResponse = (DefaultResponse) response; assertEquals(Integer.valueOf(45), defaultResponse.getCommandIdentifier()); assertEquals(ZclStatus.UNSUP_GENERAL_COMMAND, defaultResponse.getStatusCode()); assertEquals(Integer.valueOf(tid), defaultResponse.getTransactionId()); Mockito.when(command.isManufacturerSpecific()).thenReturn(true); Mockito.when(command.getTransactionId()).thenReturn(++tid); Mockito.when(command.isGenericCommand()).thenReturn(true); cluster.handleCommand(command); Mockito.verify(endpoint, Mockito.timeout(TIMEOUT).times(3)).sendTransaction(commandCapture.capture()); response = commandCapture.getValue(); assertTrue(response instanceof DefaultResponse); System.out.println(response); defaultResponse = (DefaultResponse) response; assertEquals(Integer.valueOf(45), defaultResponse.getCommandIdentifier()); assertEquals(ZclStatus.UNSUP_MANUF_GENERAL_COMMAND, defaultResponse.getStatusCode()); assertEquals(Integer.valueOf(tid), defaultResponse.getTransactionId()); Mockito.when(command.isGenericCommand()).thenReturn(false); Mockito.when(command.getTransactionId()).thenReturn(++tid); cluster.handleCommand(command); Mockito.verify(endpoint, Mockito.timeout(TIMEOUT).times(4)).sendTransaction(commandCapture.capture()); response = commandCapture.getValue(); assertTrue(response instanceof DefaultResponse); System.out.println(response); defaultResponse = (DefaultResponse) response; assertEquals(Integer.valueOf(45), defaultResponse.getCommandIdentifier()); assertEquals(ZclStatus.UNSUP_MANUF_CLUSTER_COMMAND, defaultResponse.getStatusCode()); assertEquals(Integer.valueOf(tid), defaultResponse.getTransactionId()); command = new ConfigureReportingResponse(null, null); command.setTransactionId(++tid); command.setDestinationAddress(new ZigBeeEndpointAddress(0, 0)); command.setClusterId(0x0000); ArgumentCaptor<ZclCommand> zclCommandCapture = ArgumentCaptor.forClass(ZclCommand.class); cluster.handleCommand(command); Mockito.verify(listenerMock, Mockito.timeout(TIMEOUT).times(5)).commandReceived(zclCommandCapture.capture()); assertEquals(command, zclCommandCapture.getValue()); Mockito.verify(endpoint, Mockito.timeout(TIMEOUT).times(5)).sendTransaction(commandCapture.capture()); response = commandCapture.getValue(); assertTrue(response instanceof DefaultResponse); System.out.println(response); defaultResponse = (DefaultResponse) response; assertEquals(ZclStatus.SUCCESS, defaultResponse.getStatusCode()); Mockito.when(listenerMock.commandReceived(command)).thenReturn(true); command.setTransactionId(++tid); cluster.handleCommand(command); assertEquals(command, zclCommandCapture.getValue()); Mockito.verify(endpoint, Mockito.timeout(TIMEOUT).times(5)).sendTransaction(commandCapture.capture()); cluster.removeCommandListener(listenerMock); assertEquals(0, commandListeners.size()); }
public void handleCommand(ZclCommand command) { logger.trace("{}: ZclCluster.handleCommand({})", zigbeeEndpoint.getEndpointAddress(), command); if (command instanceof ReportAttributesCommand) { handleAttributeReport((ReportAttributesCommand) command); return; } if (command instanceof ReadAttributesResponse) { handleAttributeStatus((ReadAttributesResponse) command); return; } if (command instanceof ReadAttributesCommand) { handleReadAttributes((ReadAttributesCommand) command); return; } if (command instanceof DiscoverAttributesCommand) { handleDiscoverAttributes((DiscoverAttributesCommand) command); return; } if (command instanceof WriteAttributesCommand) { handleWriteAttributesCommand((WriteAttributesCommand) command); return; } ZclStatus responseStatus; if (notifyCommandListener(command)) { return; } else if (supportedGenericCommands.contains(command.getClass())) { responseStatus = ZclStatus.SUCCESS; } else if (command.isManufacturerSpecific()) { if (command.isGenericCommand()) { responseStatus = ZclStatus.UNSUP_MANUF_GENERAL_COMMAND; } else { responseStatus = ZclStatus.UNSUP_MANUF_CLUSTER_COMMAND; } } else { if (command.isGenericCommand()) { responseStatus = ZclStatus.UNSUP_GENERAL_COMMAND; } else { responseStatus = ZclStatus.UNSUP_CLUSTER_COMMAND; } } sendDefaultResponse(command, responseStatus); }
ZclCluster { public void handleCommand(ZclCommand command) { logger.trace("{}: ZclCluster.handleCommand({})", zigbeeEndpoint.getEndpointAddress(), command); if (command instanceof ReportAttributesCommand) { handleAttributeReport((ReportAttributesCommand) command); return; } if (command instanceof ReadAttributesResponse) { handleAttributeStatus((ReadAttributesResponse) command); return; } if (command instanceof ReadAttributesCommand) { handleReadAttributes((ReadAttributesCommand) command); return; } if (command instanceof DiscoverAttributesCommand) { handleDiscoverAttributes((DiscoverAttributesCommand) command); return; } if (command instanceof WriteAttributesCommand) { handleWriteAttributesCommand((WriteAttributesCommand) command); return; } ZclStatus responseStatus; if (notifyCommandListener(command)) { return; } else if (supportedGenericCommands.contains(command.getClass())) { responseStatus = ZclStatus.SUCCESS; } else if (command.isManufacturerSpecific()) { if (command.isGenericCommand()) { responseStatus = ZclStatus.UNSUP_MANUF_GENERAL_COMMAND; } else { responseStatus = ZclStatus.UNSUP_MANUF_CLUSTER_COMMAND; } } else { if (command.isGenericCommand()) { responseStatus = ZclStatus.UNSUP_GENERAL_COMMAND; } else { responseStatus = ZclStatus.UNSUP_CLUSTER_COMMAND; } } sendDefaultResponse(command, responseStatus); } }
ZclCluster { public void handleCommand(ZclCommand command) { logger.trace("{}: ZclCluster.handleCommand({})", zigbeeEndpoint.getEndpointAddress(), command); if (command instanceof ReportAttributesCommand) { handleAttributeReport((ReportAttributesCommand) command); return; } if (command instanceof ReadAttributesResponse) { handleAttributeStatus((ReadAttributesResponse) command); return; } if (command instanceof ReadAttributesCommand) { handleReadAttributes((ReadAttributesCommand) command); return; } if (command instanceof DiscoverAttributesCommand) { handleDiscoverAttributes((DiscoverAttributesCommand) command); return; } if (command instanceof WriteAttributesCommand) { handleWriteAttributesCommand((WriteAttributesCommand) command); return; } ZclStatus responseStatus; if (notifyCommandListener(command)) { return; } else if (supportedGenericCommands.contains(command.getClass())) { responseStatus = ZclStatus.SUCCESS; } else if (command.isManufacturerSpecific()) { if (command.isGenericCommand()) { responseStatus = ZclStatus.UNSUP_MANUF_GENERAL_COMMAND; } else { responseStatus = ZclStatus.UNSUP_MANUF_CLUSTER_COMMAND; } } else { if (command.isGenericCommand()) { responseStatus = ZclStatus.UNSUP_GENERAL_COMMAND; } else { responseStatus = ZclStatus.UNSUP_CLUSTER_COMMAND; } } sendDefaultResponse(command, responseStatus); } protected  ZclCluster(ZigBeeEndpoint zigbeeEndpoint, int clusterId, String clusterName); }
ZclCluster { public void handleCommand(ZclCommand command) { logger.trace("{}: ZclCluster.handleCommand({})", zigbeeEndpoint.getEndpointAddress(), command); if (command instanceof ReportAttributesCommand) { handleAttributeReport((ReportAttributesCommand) command); return; } if (command instanceof ReadAttributesResponse) { handleAttributeStatus((ReadAttributesResponse) command); return; } if (command instanceof ReadAttributesCommand) { handleReadAttributes((ReadAttributesCommand) command); return; } if (command instanceof DiscoverAttributesCommand) { handleDiscoverAttributes((DiscoverAttributesCommand) command); return; } if (command instanceof WriteAttributesCommand) { handleWriteAttributesCommand((WriteAttributesCommand) command); return; } ZclStatus responseStatus; if (notifyCommandListener(command)) { return; } else if (supportedGenericCommands.contains(command.getClass())) { responseStatus = ZclStatus.SUCCESS; } else if (command.isManufacturerSpecific()) { if (command.isGenericCommand()) { responseStatus = ZclStatus.UNSUP_MANUF_GENERAL_COMMAND; } else { responseStatus = ZclStatus.UNSUP_MANUF_CLUSTER_COMMAND; } } else { if (command.isGenericCommand()) { responseStatus = ZclStatus.UNSUP_GENERAL_COMMAND; } else { responseStatus = ZclStatus.UNSUP_CLUSTER_COMMAND; } } sendDefaultResponse(command, responseStatus); } protected  ZclCluster(ZigBeeEndpoint zigbeeEndpoint, int clusterId, String clusterName); Future<CommandResult> sendCommand(ZclGeneralCommand command); void sendDefaultResponse(ZclCommand command, ZclStatus status); @Deprecated void sendDefaultResponse(Integer transactionId, Integer commandIdentifier, ZclStatus status,
            Integer manufacturerCode); @Deprecated void sendDefaultResponse(Integer transactionId, Integer commandIdentifier, ZclStatus status); Future<CommandResult> writeAttribute(final int attributeId, final ZclDataType dataType, final Object value); Future<CommandResult> writeAttributes(List<WriteAttributeRecord> attributes); Future<CommandResult> readAttribute(final int attributeId); Future<CommandResult> readAttributes(final List<Integer> attributeIds); Future<CommandResult> reportAttribute(final int attributeId, final ZclDataType dataType,
            final Object value); Future<CommandResult> reportAttributes(List<AttributeReport> attributes); Future<CommandResult> setReporting(final int attributeId, final int minInterval, final int maxInterval,
            Object reportableChange); Future<CommandResult> setReporting(final int attributeId, final int minInterval, final int maxInterval); Future<CommandResult> getReporting(final int attributeId); Collection<ZclAttribute> getAttributes(); ZclAttribute getAttribute(int attributeId); ZclAttribute getLocalAttribute(int attributeId); Collection<ZclAttribute> getLocalAttributes(); Integer getClusterId(); String getClusterName(); ZigBeeEndpointAddress getZigBeeAddress(); void setServer(); boolean isServer(); void setClient(); boolean isClient(); void setApsSecurityRequired(boolean requireApsSecurity); boolean getApsSecurityRequired(); Future<CommandResult> bind(IeeeAddress address, int endpointId); Future<CommandResult> unbind(IeeeAddress address, int endpointId); Set<Integer> getSupportedAttributes(); boolean isAttributeSupported(int attributeId); Future<Boolean> discoverAttributes(final boolean rediscover); Future<Boolean> discoverAttributes(final boolean rediscover, final Integer manufacturerCode); Set<Integer> getSupportedCommandsReceived(); boolean isReceivedCommandSupported(int commandId); Future<Boolean> discoverCommandsReceived(final boolean rediscover); Future<Boolean> discoverCommandsReceived(final boolean rediscover, final Integer manufacturerCode); Set<Integer> getSupportedCommandsGenerated(); boolean isGeneratedCommandSupported(int commandId); Future<Boolean> discoverCommandsGenerated(final boolean rediscover); Future<Boolean> discoverCommandsGenerated(final boolean rediscover, final Integer manufacturerCode); void addAttributeListener(ZclAttributeListener listener); void removeAttributeListener(final ZclAttributeListener listener); void addCommandListener(ZclCommandListener listener); void removeCommandListener(final ZclCommandListener listener); void handleCommand(ZclCommand command); ZclCommand getCommandFromId(ZclFrameType zclFrameType, int commandId); ZclCommand getResponseFromId(ZclFrameType zclFrameType, int commandId); ZclClusterDao getDao(); void setDao(ZclClusterDao dao); @Deprecated Future<CommandResult> write(final int attribute, final ZclDataType dataType, final Object value); @Deprecated Future<CommandResult> write(final ZclAttribute attribute, final Object value); @Deprecated Future<CommandResult> read(final int attribute); @Deprecated Future<CommandResult> read(final ZclAttribute attribute); @Deprecated Future<CommandResult> read(final List<Integer> attributes); @Deprecated Future<CommandResult> setReporting(final ZclAttribute attribute, final int minInterval,
            final int maxInterval, final Object reportableChange); @Deprecated Future<CommandResult> setReporting(final ZclAttribute attribute, final int minInterval,
            final int maxInterval); @Deprecated Future<CommandResult> getReporting(final ZclAttribute attribute); boolean isManufacturerSpecific(); Integer getManufacturerCode(); void addAttributes(Set<ZclAttribute> attributes); void addLocalAttributes(Set<ZclAttribute> attributes); void addClientCommands(Map<Integer, Class<? extends ZclCommand>> commands); void addServerCommands(Map<Integer, Class<? extends ZclCommand>> commands); static DefaultResponse createDefaultResponse(ZclCommand command, ZclStatus status); NotificationService getNotificationService(); }
ZclCluster { public void handleCommand(ZclCommand command) { logger.trace("{}: ZclCluster.handleCommand({})", zigbeeEndpoint.getEndpointAddress(), command); if (command instanceof ReportAttributesCommand) { handleAttributeReport((ReportAttributesCommand) command); return; } if (command instanceof ReadAttributesResponse) { handleAttributeStatus((ReadAttributesResponse) command); return; } if (command instanceof ReadAttributesCommand) { handleReadAttributes((ReadAttributesCommand) command); return; } if (command instanceof DiscoverAttributesCommand) { handleDiscoverAttributes((DiscoverAttributesCommand) command); return; } if (command instanceof WriteAttributesCommand) { handleWriteAttributesCommand((WriteAttributesCommand) command); return; } ZclStatus responseStatus; if (notifyCommandListener(command)) { return; } else if (supportedGenericCommands.contains(command.getClass())) { responseStatus = ZclStatus.SUCCESS; } else if (command.isManufacturerSpecific()) { if (command.isGenericCommand()) { responseStatus = ZclStatus.UNSUP_MANUF_GENERAL_COMMAND; } else { responseStatus = ZclStatus.UNSUP_MANUF_CLUSTER_COMMAND; } } else { if (command.isGenericCommand()) { responseStatus = ZclStatus.UNSUP_GENERAL_COMMAND; } else { responseStatus = ZclStatus.UNSUP_CLUSTER_COMMAND; } } sendDefaultResponse(command, responseStatus); } protected  ZclCluster(ZigBeeEndpoint zigbeeEndpoint, int clusterId, String clusterName); Future<CommandResult> sendCommand(ZclGeneralCommand command); void sendDefaultResponse(ZclCommand command, ZclStatus status); @Deprecated void sendDefaultResponse(Integer transactionId, Integer commandIdentifier, ZclStatus status,
            Integer manufacturerCode); @Deprecated void sendDefaultResponse(Integer transactionId, Integer commandIdentifier, ZclStatus status); Future<CommandResult> writeAttribute(final int attributeId, final ZclDataType dataType, final Object value); Future<CommandResult> writeAttributes(List<WriteAttributeRecord> attributes); Future<CommandResult> readAttribute(final int attributeId); Future<CommandResult> readAttributes(final List<Integer> attributeIds); Future<CommandResult> reportAttribute(final int attributeId, final ZclDataType dataType,
            final Object value); Future<CommandResult> reportAttributes(List<AttributeReport> attributes); Future<CommandResult> setReporting(final int attributeId, final int minInterval, final int maxInterval,
            Object reportableChange); Future<CommandResult> setReporting(final int attributeId, final int minInterval, final int maxInterval); Future<CommandResult> getReporting(final int attributeId); Collection<ZclAttribute> getAttributes(); ZclAttribute getAttribute(int attributeId); ZclAttribute getLocalAttribute(int attributeId); Collection<ZclAttribute> getLocalAttributes(); Integer getClusterId(); String getClusterName(); ZigBeeEndpointAddress getZigBeeAddress(); void setServer(); boolean isServer(); void setClient(); boolean isClient(); void setApsSecurityRequired(boolean requireApsSecurity); boolean getApsSecurityRequired(); Future<CommandResult> bind(IeeeAddress address, int endpointId); Future<CommandResult> unbind(IeeeAddress address, int endpointId); Set<Integer> getSupportedAttributes(); boolean isAttributeSupported(int attributeId); Future<Boolean> discoverAttributes(final boolean rediscover); Future<Boolean> discoverAttributes(final boolean rediscover, final Integer manufacturerCode); Set<Integer> getSupportedCommandsReceived(); boolean isReceivedCommandSupported(int commandId); Future<Boolean> discoverCommandsReceived(final boolean rediscover); Future<Boolean> discoverCommandsReceived(final boolean rediscover, final Integer manufacturerCode); Set<Integer> getSupportedCommandsGenerated(); boolean isGeneratedCommandSupported(int commandId); Future<Boolean> discoverCommandsGenerated(final boolean rediscover); Future<Boolean> discoverCommandsGenerated(final boolean rediscover, final Integer manufacturerCode); void addAttributeListener(ZclAttributeListener listener); void removeAttributeListener(final ZclAttributeListener listener); void addCommandListener(ZclCommandListener listener); void removeCommandListener(final ZclCommandListener listener); void handleCommand(ZclCommand command); ZclCommand getCommandFromId(ZclFrameType zclFrameType, int commandId); ZclCommand getResponseFromId(ZclFrameType zclFrameType, int commandId); ZclClusterDao getDao(); void setDao(ZclClusterDao dao); @Deprecated Future<CommandResult> write(final int attribute, final ZclDataType dataType, final Object value); @Deprecated Future<CommandResult> write(final ZclAttribute attribute, final Object value); @Deprecated Future<CommandResult> read(final int attribute); @Deprecated Future<CommandResult> read(final ZclAttribute attribute); @Deprecated Future<CommandResult> read(final List<Integer> attributes); @Deprecated Future<CommandResult> setReporting(final ZclAttribute attribute, final int minInterval,
            final int maxInterval, final Object reportableChange); @Deprecated Future<CommandResult> setReporting(final ZclAttribute attribute, final int minInterval,
            final int maxInterval); @Deprecated Future<CommandResult> getReporting(final ZclAttribute attribute); boolean isManufacturerSpecific(); Integer getManufacturerCode(); void addAttributes(Set<ZclAttribute> attributes); void addLocalAttributes(Set<ZclAttribute> attributes); void addClientCommands(Map<Integer, Class<? extends ZclCommand>> commands); void addServerCommands(Map<Integer, Class<? extends ZclCommand>> commands); static DefaultResponse createDefaultResponse(ZclCommand command, ZclStatus status); NotificationService getNotificationService();  }