@Test public void handleWriteAttributesCommand() { 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<WriteAttributeRecord> records = new ArrayList<>(); WriteAttributeRecord record = new WriteAttributeRecord(); record.setAttributeIdentifier(1); record.setAttributeDataType(ZclDataType.UNSIGNED_8_BIT_INTEGER); record.setAttributeValue(Integer.valueOf(123)); records.add(record); WriteAttributesCommand command = new WriteAttributesCommand(records); command.setClusterId(ZclBasicCluster.CLUSTER_ID); command.setSourceAddress(new ZigBeeEndpointAddress(1234)); command.setDestinationAddress(new ZigBeeEndpointAddress(5678)); command.setCommandDirection(ZclCommandDirection.CLIENT_TO_SERVER); command.setTransactionId(55); cluster.handleCommand(command); assertEquals(1, commandCapture.getAllValues().size()); WriteAttributesResponse response = (WriteAttributesResponse) commandCapture.getValue(); System.out.println(response); assertEquals(Integer.valueOf(ZclBasicCluster.CLUSTER_ID), response.getClusterId()); assertEquals(ZclCommandDirection.SERVER_TO_CLIENT, response.getCommandDirection()); assertEquals(1, response.getRecords().size()); assertEquals(Integer.valueOf(55), response.getTransactionId()); List<WriteAttributeStatusRecord> responseRecords = response.getRecords(); assertEquals(1, responseRecords.size()); assertEquals(ZclStatus.SUCCESS, responseRecords.get(0).getStatus()); record = new WriteAttributeRecord(); record.setAttributeIdentifier(2); record.setAttributeDataType(ZclDataType.BOOLEAN); record.setAttributeValue(false); records.add(record); cluster.handleCommand(command); assertEquals(2, commandCapture.getAllValues().size()); response = (WriteAttributesResponse) commandCapture.getValue(); System.out.println(response); responseRecords = response.getRecords(); assertEquals(1, responseRecords.size()); assertEquals(ZclStatus.SUCCESS, responseRecords.get(0).getStatus()); record = new WriteAttributeRecord(); record.setAttributeIdentifier(3); record.setAttributeDataType(ZclDataType.BOOLEAN); record.setAttributeValue(false); records.add(record); record = new WriteAttributeRecord(); record.setAttributeIdentifier(10); record.setAttributeDataType(ZclDataType.BOOLEAN); record.setAttributeValue(true); records.add(record); cluster.handleCommand(command); assertEquals(3, commandCapture.getAllValues().size()); response = (WriteAttributesResponse) commandCapture.getValue(); System.out.println(response); responseRecords = response.getRecords(); assertEquals(4, responseRecords.size()); assertEquals(1, responseRecords.get(0).getAttributeIdentifier()); assertEquals(2, responseRecords.get(1).getAttributeIdentifier()); assertEquals(3, responseRecords.get(2).getAttributeIdentifier()); assertEquals(10, responseRecords.get(3).getAttributeIdentifier()); assertEquals(ZclStatus.SUCCESS, responseRecords.get(0).getStatus()); assertEquals(ZclStatus.SUCCESS, responseRecords.get(1).getStatus()); assertEquals(ZclStatus.UNSUPPORTED_ATTRIBUTE, responseRecords.get(2).getStatus()); assertEquals(ZclStatus.INVALID_DATA_TYPE, responseRecords.get(3).getStatus()); }
private void handleWriteAttributesCommand(WriteAttributesCommand command) { logger.trace("{}: ZclCluster.handleWriteAttributesCommand({})", zigbeeEndpoint.getEndpointAddress(), command.getRecords()); boolean success = true; List<WriteAttributeStatusRecord> attributeStatus = new ArrayList<>(); for (WriteAttributeRecord requestRecord : command.getRecords()) { ZclAttribute attribute = getLocalAttribute(requestRecord.getAttributeIdentifier()); WriteAttributeStatusRecord responseRecord = new WriteAttributeStatusRecord(); responseRecord.setAttributeIdentifier(requestRecord.getAttributeIdentifier()); if (attribute == null || !attribute.isImplemented()) { responseRecord.setStatus(ZclStatus.UNSUPPORTED_ATTRIBUTE); success = false; } else if (attribute.getDataType() != requestRecord.getAttributeDataType()) { responseRecord.setStatus(ZclStatus.INVALID_DATA_TYPE); success = false; } else { attribute.setValue( normalizer.normalizeZclData(attribute.getDataType(), requestRecord.getAttributeValue())); responseRecord.setStatus(ZclStatus.SUCCESS); logger.debug("{}: Local attribute {} updated to {} for cluster {}", zigbeeEndpoint.getEndpointAddress(), attribute.getId(), attribute.getLastValue(), clusterId); } attributeStatus.add(responseRecord); } WriteAttributesResponse response = new WriteAttributesResponse(attributeStatus); if (success) { WriteAttributeStatusRecord responseRecord = new WriteAttributeStatusRecord(); responseRecord.setStatus(ZclStatus.SUCCESS); attributeStatus.clear(); attributeStatus.add(responseRecord); } sendResponse(command, response); }
ZclCluster { private void handleWriteAttributesCommand(WriteAttributesCommand command) { logger.trace("{}: ZclCluster.handleWriteAttributesCommand({})", zigbeeEndpoint.getEndpointAddress(), command.getRecords()); boolean success = true; List<WriteAttributeStatusRecord> attributeStatus = new ArrayList<>(); for (WriteAttributeRecord requestRecord : command.getRecords()) { ZclAttribute attribute = getLocalAttribute(requestRecord.getAttributeIdentifier()); WriteAttributeStatusRecord responseRecord = new WriteAttributeStatusRecord(); responseRecord.setAttributeIdentifier(requestRecord.getAttributeIdentifier()); if (attribute == null || !attribute.isImplemented()) { responseRecord.setStatus(ZclStatus.UNSUPPORTED_ATTRIBUTE); success = false; } else if (attribute.getDataType() != requestRecord.getAttributeDataType()) { responseRecord.setStatus(ZclStatus.INVALID_DATA_TYPE); success = false; } else { attribute.setValue( normalizer.normalizeZclData(attribute.getDataType(), requestRecord.getAttributeValue())); responseRecord.setStatus(ZclStatus.SUCCESS); logger.debug("{}: Local attribute {} updated to {} for cluster {}", zigbeeEndpoint.getEndpointAddress(), attribute.getId(), attribute.getLastValue(), clusterId); } attributeStatus.add(responseRecord); } WriteAttributesResponse response = new WriteAttributesResponse(attributeStatus); if (success) { WriteAttributeStatusRecord responseRecord = new WriteAttributeStatusRecord(); responseRecord.setStatus(ZclStatus.SUCCESS); attributeStatus.clear(); attributeStatus.add(responseRecord); } sendResponse(command, response); } }
ZclCluster { private void handleWriteAttributesCommand(WriteAttributesCommand command) { logger.trace("{}: ZclCluster.handleWriteAttributesCommand({})", zigbeeEndpoint.getEndpointAddress(), command.getRecords()); boolean success = true; List<WriteAttributeStatusRecord> attributeStatus = new ArrayList<>(); for (WriteAttributeRecord requestRecord : command.getRecords()) { ZclAttribute attribute = getLocalAttribute(requestRecord.getAttributeIdentifier()); WriteAttributeStatusRecord responseRecord = new WriteAttributeStatusRecord(); responseRecord.setAttributeIdentifier(requestRecord.getAttributeIdentifier()); if (attribute == null || !attribute.isImplemented()) { responseRecord.setStatus(ZclStatus.UNSUPPORTED_ATTRIBUTE); success = false; } else if (attribute.getDataType() != requestRecord.getAttributeDataType()) { responseRecord.setStatus(ZclStatus.INVALID_DATA_TYPE); success = false; } else { attribute.setValue( normalizer.normalizeZclData(attribute.getDataType(), requestRecord.getAttributeValue())); responseRecord.setStatus(ZclStatus.SUCCESS); logger.debug("{}: Local attribute {} updated to {} for cluster {}", zigbeeEndpoint.getEndpointAddress(), attribute.getId(), attribute.getLastValue(), clusterId); } attributeStatus.add(responseRecord); } WriteAttributesResponse response = new WriteAttributesResponse(attributeStatus); if (success) { WriteAttributeStatusRecord responseRecord = new WriteAttributeStatusRecord(); responseRecord.setStatus(ZclStatus.SUCCESS); attributeStatus.clear(); attributeStatus.add(responseRecord); } sendResponse(command, response); } protected  ZclCluster(ZigBeeEndpoint zigbeeEndpoint, int clusterId, String clusterName); }
ZclCluster { private void handleWriteAttributesCommand(WriteAttributesCommand command) { logger.trace("{}: ZclCluster.handleWriteAttributesCommand({})", zigbeeEndpoint.getEndpointAddress(), command.getRecords()); boolean success = true; List<WriteAttributeStatusRecord> attributeStatus = new ArrayList<>(); for (WriteAttributeRecord requestRecord : command.getRecords()) { ZclAttribute attribute = getLocalAttribute(requestRecord.getAttributeIdentifier()); WriteAttributeStatusRecord responseRecord = new WriteAttributeStatusRecord(); responseRecord.setAttributeIdentifier(requestRecord.getAttributeIdentifier()); if (attribute == null || !attribute.isImplemented()) { responseRecord.setStatus(ZclStatus.UNSUPPORTED_ATTRIBUTE); success = false; } else if (attribute.getDataType() != requestRecord.getAttributeDataType()) { responseRecord.setStatus(ZclStatus.INVALID_DATA_TYPE); success = false; } else { attribute.setValue( normalizer.normalizeZclData(attribute.getDataType(), requestRecord.getAttributeValue())); responseRecord.setStatus(ZclStatus.SUCCESS); logger.debug("{}: Local attribute {} updated to {} for cluster {}", zigbeeEndpoint.getEndpointAddress(), attribute.getId(), attribute.getLastValue(), clusterId); } attributeStatus.add(responseRecord); } WriteAttributesResponse response = new WriteAttributesResponse(attributeStatus); if (success) { WriteAttributeStatusRecord responseRecord = new WriteAttributeStatusRecord(); responseRecord.setStatus(ZclStatus.SUCCESS); attributeStatus.clear(); attributeStatus.add(responseRecord); } 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 handleWriteAttributesCommand(WriteAttributesCommand command) { logger.trace("{}: ZclCluster.handleWriteAttributesCommand({})", zigbeeEndpoint.getEndpointAddress(), command.getRecords()); boolean success = true; List<WriteAttributeStatusRecord> attributeStatus = new ArrayList<>(); for (WriteAttributeRecord requestRecord : command.getRecords()) { ZclAttribute attribute = getLocalAttribute(requestRecord.getAttributeIdentifier()); WriteAttributeStatusRecord responseRecord = new WriteAttributeStatusRecord(); responseRecord.setAttributeIdentifier(requestRecord.getAttributeIdentifier()); if (attribute == null || !attribute.isImplemented()) { responseRecord.setStatus(ZclStatus.UNSUPPORTED_ATTRIBUTE); success = false; } else if (attribute.getDataType() != requestRecord.getAttributeDataType()) { responseRecord.setStatus(ZclStatus.INVALID_DATA_TYPE); success = false; } else { attribute.setValue( normalizer.normalizeZclData(attribute.getDataType(), requestRecord.getAttributeValue())); responseRecord.setStatus(ZclStatus.SUCCESS); logger.debug("{}: Local attribute {} updated to {} for cluster {}", zigbeeEndpoint.getEndpointAddress(), attribute.getId(), attribute.getLastValue(), clusterId); } attributeStatus.add(responseRecord); } WriteAttributesResponse response = new WriteAttributesResponse(attributeStatus); if (success) { WriteAttributeStatusRecord responseRecord = new WriteAttributeStatusRecord(); responseRecord.setStatus(ZclStatus.SUCCESS); attributeStatus.clear(); attributeStatus.add(responseRecord); } 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();  }