@Test public void handleReadAttributes() { createEndpoint(); ZclOnOffCluster cluster = new ZclOnOffCluster(endpoint); Set<ZclAttribute> attributes = new HashSet<>(); attributes.add(new ZclAttribute(cluster, 1, "Attribute-1", ZclDataType.UNSIGNED_8_BIT_INTEGER, true, true, false, true)); attributes.add(new ZclAttribute(cluster, 2, "Attribute-2", ZclDataType.BOOLEAN, true, true, false, true)); attributes.add( new ZclAttribute(cluster, 10, "Attribute-10", ZclDataType.CHARACTER_STRING, true, true, false, true)); attributes.add(new ZclAttribute(cluster, 11, "Attribute-11", ZclDataType.BOOLEAN, true, true, false, true)); attributes.add(new ZclAttribute(cluster, 13, "Attribute-13", ZclDataType.BOOLEAN, true, true, false, true)); cluster.addLocalAttributes(attributes); List<Integer> identifiers = new ArrayList<>(); identifiers.add(2); ReadAttributesCommand readCommand = getReadAttributesCommand(identifiers); cluster.handleCommand(readCommand); assertEquals(1, commandCapture.getAllValues().size()); ReadAttributesResponse readResponse = (ReadAttributesResponse) commandCapture.getValue(); System.out.println(readResponse); assertEquals(Integer.valueOf(ZclOnOffCluster.CLUSTER_ID), readResponse.getClusterId()); assertEquals(ZclCommandDirection.SERVER_TO_CLIENT, readResponse.getCommandDirection()); assertEquals(1, readResponse.getRecords().size()); assertEquals(Integer.valueOf(55), readResponse.getTransactionId()); List<ReadAttributeStatusRecord> records = readResponse.getRecords(); assertEquals(2, records.get(0).getAttributeIdentifier()); assertNull(records.get(0).getAttributeValue()); assertEquals(ZclStatus.INVALID_VALUE, records.get(0).getStatus()); cluster.getLocalAttribute(2).setValue(false); cluster.handleCommand(readCommand); assertEquals(2, commandCapture.getAllValues().size()); readResponse = (ReadAttributesResponse) commandCapture.getValue(); System.out.println(readResponse); records = readResponse.getRecords(); assertEquals(2, records.get(0).getAttributeIdentifier()); assertEquals(false, records.get(0).getAttributeValue()); assertEquals(ZclStatus.SUCCESS, records.get(0).getStatus()); cluster.getLocalAttribute(13).setValue(true); identifiers = new ArrayList<>(); identifiers.add(2); identifiers.add(13); identifiers.add(55); readCommand = getReadAttributesCommand(identifiers); cluster.handleCommand(readCommand); assertEquals(3, commandCapture.getAllValues().size()); readResponse = (ReadAttributesResponse) commandCapture.getValue(); System.out.println(readResponse); records = readResponse.getRecords(); assertEquals(3, records.size()); assertEquals(2, records.get(0).getAttributeIdentifier()); assertEquals(false, records.get(0).getAttributeValue()); assertEquals(ZclStatus.SUCCESS, records.get(0).getStatus()); assertEquals(13, records.get(1).getAttributeIdentifier()); assertEquals(true, records.get(1).getAttributeValue()); assertEquals(ZclStatus.SUCCESS, records.get(1).getStatus()); assertEquals(55, records.get(2).getAttributeIdentifier()); assertEquals(ZclStatus.UNSUPPORTED_ATTRIBUTE, records.get(2).getStatus()); }
private void handleReadAttributes(ReadAttributesCommand command) { Map<Integer, ZclAttribute> localAttributes; if (isClient) { localAttributes = serverAttributes; } else { localAttributes = clientAttributes; } List<ReadAttributeStatusRecord> attributeRecords = new ArrayList<>(); for (int attributeId : command.getIdentifiers()) { ReadAttributeStatusRecord record = new ReadAttributeStatusRecord(); record.setAttributeIdentifier(attributeId); if (localAttributes.containsKey(attributeId) && localAttributes.get(attributeId) != null && localAttributes.get(attributeId).isImplemented()) { if (localAttributes.get(attributeId).getLastValue() != null) { record.setStatus(ZclStatus.SUCCESS); record.setAttributeDataType(localAttributes.get(attributeId).getDataType()); record.setAttributeValue(localAttributes.get(attributeId).getLastValue()); } else { record.setStatus(ZclStatus.INVALID_VALUE); } } else { record.setStatus(ZclStatus.UNSUPPORTED_ATTRIBUTE); } attributeRecords.add(record); } ReadAttributesResponse response = new ReadAttributesResponse(attributeRecords); response.setClusterId(clusterId); sendResponse(command, response); }
ZclCluster { private void handleReadAttributes(ReadAttributesCommand command) { Map<Integer, ZclAttribute> localAttributes; if (isClient) { localAttributes = serverAttributes; } else { localAttributes = clientAttributes; } List<ReadAttributeStatusRecord> attributeRecords = new ArrayList<>(); for (int attributeId : command.getIdentifiers()) { ReadAttributeStatusRecord record = new ReadAttributeStatusRecord(); record.setAttributeIdentifier(attributeId); if (localAttributes.containsKey(attributeId) && localAttributes.get(attributeId) != null && localAttributes.get(attributeId).isImplemented()) { if (localAttributes.get(attributeId).getLastValue() != null) { record.setStatus(ZclStatus.SUCCESS); record.setAttributeDataType(localAttributes.get(attributeId).getDataType()); record.setAttributeValue(localAttributes.get(attributeId).getLastValue()); } else { record.setStatus(ZclStatus.INVALID_VALUE); } } else { record.setStatus(ZclStatus.UNSUPPORTED_ATTRIBUTE); } attributeRecords.add(record); } ReadAttributesResponse response = new ReadAttributesResponse(attributeRecords); response.setClusterId(clusterId); sendResponse(command, response); } }
ZclCluster { private void handleReadAttributes(ReadAttributesCommand command) { Map<Integer, ZclAttribute> localAttributes; if (isClient) { localAttributes = serverAttributes; } else { localAttributes = clientAttributes; } List<ReadAttributeStatusRecord> attributeRecords = new ArrayList<>(); for (int attributeId : command.getIdentifiers()) { ReadAttributeStatusRecord record = new ReadAttributeStatusRecord(); record.setAttributeIdentifier(attributeId); if (localAttributes.containsKey(attributeId) && localAttributes.get(attributeId) != null && localAttributes.get(attributeId).isImplemented()) { if (localAttributes.get(attributeId).getLastValue() != null) { record.setStatus(ZclStatus.SUCCESS); record.setAttributeDataType(localAttributes.get(attributeId).getDataType()); record.setAttributeValue(localAttributes.get(attributeId).getLastValue()); } else { record.setStatus(ZclStatus.INVALID_VALUE); } } else { record.setStatus(ZclStatus.UNSUPPORTED_ATTRIBUTE); } attributeRecords.add(record); } ReadAttributesResponse response = new ReadAttributesResponse(attributeRecords); response.setClusterId(clusterId); sendResponse(command, response); } protected  ZclCluster(ZigBeeEndpoint zigbeeEndpoint, int clusterId, String clusterName); }
ZclCluster { private void handleReadAttributes(ReadAttributesCommand command) { Map<Integer, ZclAttribute> localAttributes; if (isClient) { localAttributes = serverAttributes; } else { localAttributes = clientAttributes; } List<ReadAttributeStatusRecord> attributeRecords = new ArrayList<>(); for (int attributeId : command.getIdentifiers()) { ReadAttributeStatusRecord record = new ReadAttributeStatusRecord(); record.setAttributeIdentifier(attributeId); if (localAttributes.containsKey(attributeId) && localAttributes.get(attributeId) != null && localAttributes.get(attributeId).isImplemented()) { if (localAttributes.get(attributeId).getLastValue() != null) { record.setStatus(ZclStatus.SUCCESS); record.setAttributeDataType(localAttributes.get(attributeId).getDataType()); record.setAttributeValue(localAttributes.get(attributeId).getLastValue()); } else { record.setStatus(ZclStatus.INVALID_VALUE); } } else { record.setStatus(ZclStatus.UNSUPPORTED_ATTRIBUTE); } attributeRecords.add(record); } ReadAttributesResponse response = new ReadAttributesResponse(attributeRecords); response.setClusterId(clusterId); sendResponse(command, response); } 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 { private void handleReadAttributes(ReadAttributesCommand command) { Map<Integer, ZclAttribute> localAttributes; if (isClient) { localAttributes = serverAttributes; } else { localAttributes = clientAttributes; } List<ReadAttributeStatusRecord> attributeRecords = new ArrayList<>(); for (int attributeId : command.getIdentifiers()) { ReadAttributeStatusRecord record = new ReadAttributeStatusRecord(); record.setAttributeIdentifier(attributeId); if (localAttributes.containsKey(attributeId) && localAttributes.get(attributeId) != null && localAttributes.get(attributeId).isImplemented()) { if (localAttributes.get(attributeId).getLastValue() != null) { record.setStatus(ZclStatus.SUCCESS); record.setAttributeDataType(localAttributes.get(attributeId).getDataType()); record.setAttributeValue(localAttributes.get(attributeId).getLastValue()); } else { record.setStatus(ZclStatus.INVALID_VALUE); } } else { record.setStatus(ZclStatus.UNSUPPORTED_ATTRIBUTE); } attributeRecords.add(record); } ReadAttributesResponse response = new ReadAttributesResponse(attributeRecords); response.setClusterId(clusterId); sendResponse(command, response); } 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();  }