Search in sources :

Example 1 with ReadAttributeStatusRecord

use of com.zsmartsystems.zigbee.zcl.field.ReadAttributeStatusRecord in project com.zsmartsystems.zigbee by zsmartsystems.

the class ReadAttributesResponseTest method testReceiveNull.

@Test
public void testReceiveNull() {
    int[] packet = getPacketData("01 00 86");
    ReadAttributesResponse response = new ReadAttributesResponse();
    DefaultDeserializer deserializer = new DefaultDeserializer(packet);
    ZclFieldDeserializer fieldDeserializer = new ZclFieldDeserializer(deserializer);
    response.deserialize(fieldDeserializer);
    System.out.println(response);
    List<ReadAttributeStatusRecord> records = response.getRecords();
    ReadAttributeStatusRecord record = records.get(0);
    assertEquals(ZclStatus.UNSUPPORTED_ATTRIBUTE, record.getStatus());
}
Also used : DefaultDeserializer(com.zsmartsystems.zigbee.serialization.DefaultDeserializer) ReadAttributeStatusRecord(com.zsmartsystems.zigbee.zcl.field.ReadAttributeStatusRecord) ZclFieldDeserializer(com.zsmartsystems.zigbee.zcl.ZclFieldDeserializer) CommandTest(com.zsmartsystems.zigbee.CommandTest) Test(org.junit.Test)

Example 2 with ReadAttributeStatusRecord

use of com.zsmartsystems.zigbee.zcl.field.ReadAttributeStatusRecord in project com.zsmartsystems.zigbee by zsmartsystems.

the class ReadAttributesResponseTest method testReceive.

@Test
public void testReceive() {
    int[] packet = getPacketData("05 00 00 42 06 4C 43 54 30 30 33 21 00 1D");
    ReadAttributesResponse response = new ReadAttributesResponse();
    DefaultDeserializer deserializer = new DefaultDeserializer(packet);
    ZclFieldDeserializer fieldDeserializer = new ZclFieldDeserializer(deserializer);
    response.deserialize(fieldDeserializer);
    System.out.println(response);
    List<ReadAttributeStatusRecord> records = response.getRecords();
    ReadAttributeStatusRecord record = records.get(0);
    assertEquals(ZclDataType.CHARACTER_STRING, record.getAttributeDataType());
    assertEquals(5, record.getAttributeIdentifier());
    assertEquals(ZclStatus.SUCCESS, record.getStatus());
    assertEquals("LCT003", record.getAttributeValue());
}
Also used : DefaultDeserializer(com.zsmartsystems.zigbee.serialization.DefaultDeserializer) ReadAttributeStatusRecord(com.zsmartsystems.zigbee.zcl.field.ReadAttributeStatusRecord) ZclFieldDeserializer(com.zsmartsystems.zigbee.zcl.ZclFieldDeserializer) CommandTest(com.zsmartsystems.zigbee.CommandTest) Test(org.junit.Test)

Example 3 with ReadAttributeStatusRecord

use of com.zsmartsystems.zigbee.zcl.field.ReadAttributeStatusRecord in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZclCluster method readSync.

/**
 * Read an attribute
 *
 * @param attribute the {@link ZclAttribute} to read
 * @return
 */
protected Object readSync(final ZclAttribute attribute) {
    logger.debug("readSync request: {}", attribute);
    CommandResult result;
    try {
        result = read(attribute).get();
    } catch (InterruptedException e) {
        logger.debug("readSync interrupted");
        return null;
    } catch (ExecutionException e) {
        logger.debug("readSync exception ", e);
        return null;
    }
    if (!result.isSuccess()) {
        return null;
    }
    ReadAttributesResponse response = result.getResponse();
    if (response.getRecords().get(0).getStatus() == ZclStatus.SUCCESS) {
        ReadAttributeStatusRecord attributeRecord = response.getRecords().get(0);
        return normalizer.normalizeZclData(attribute.getDataType(), attributeRecord.getAttributeValue());
    }
    return null;
}
Also used : ReadAttributesResponse(com.zsmartsystems.zigbee.zcl.clusters.general.ReadAttributesResponse) ReadAttributeStatusRecord(com.zsmartsystems.zigbee.zcl.field.ReadAttributeStatusRecord) ExecutionException(java.util.concurrent.ExecutionException) CommandResult(com.zsmartsystems.zigbee.CommandResult)

Example 4 with ReadAttributeStatusRecord

use of com.zsmartsystems.zigbee.zcl.field.ReadAttributeStatusRecord in project com.zsmartsystems.zigbee by zsmartsystems.

the class ReadAttributesResponseTest method testReceiveOtaImageStatus.

@Test
public void testReceiveOtaImageStatus() {
    int[] packet = getPacketData("06 00 00 20 02");
    ReadAttributesResponse response = new ReadAttributesResponse();
    DefaultDeserializer deserializer = new DefaultDeserializer(packet);
    ZclFieldDeserializer fieldDeserializer = new ZclFieldDeserializer(deserializer);
    response.deserialize(fieldDeserializer);
    System.out.println(response);
    List<ReadAttributeStatusRecord> records = response.getRecords();
    ReadAttributeStatusRecord record = records.get(0);
    assertEquals(ZclDataType.UNSIGNED_8_BIT_INTEGER, record.getAttributeDataType());
    assertEquals(6, record.getAttributeIdentifier());
    assertEquals(ZclStatus.SUCCESS, record.getStatus());
    assertEquals(2, record.getAttributeValue());
}
Also used : DefaultDeserializer(com.zsmartsystems.zigbee.serialization.DefaultDeserializer) ReadAttributeStatusRecord(com.zsmartsystems.zigbee.zcl.field.ReadAttributeStatusRecord) ZclFieldDeserializer(com.zsmartsystems.zigbee.zcl.ZclFieldDeserializer) CommandTest(com.zsmartsystems.zigbee.CommandTest) Test(org.junit.Test)

Example 5 with ReadAttributeStatusRecord

use of com.zsmartsystems.zigbee.zcl.field.ReadAttributeStatusRecord in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZclCluster method handleAttributeStatus.

/**
 * Processes a list of attribute status reports for this cluster
 *
 * @param reports {@List} of {@link ReadAttributeStatusRecord}
 */
public void handleAttributeStatus(List<ReadAttributeStatusRecord> records) {
    for (ReadAttributeStatusRecord record : records) {
        if (record.getStatus() != ZclStatus.SUCCESS) {
            logger.debug("{}: Error reading attribute {} in cluster {} - {}", zigbeeEndpoint.getEndpointAddress(), record.getAttributeIdentifier(), clusterId, record.getStatus());
            continue;
        }
        ZclAttribute attribute = attributes.get(record.getAttributeIdentifier());
        if (attribute == null) {
            logger.debug("{}: Unknown attribute {} in cluster {}", zigbeeEndpoint.getEndpointAddress(), record.getAttributeIdentifier(), clusterId);
        } else {
            attribute.updateValue(normalizer.normalizeZclData(attribute.getDataType(), record.getAttributeValue()));
            notifyAttributeListener(attribute);
        }
    }
}
Also used : ReadAttributeStatusRecord(com.zsmartsystems.zigbee.zcl.field.ReadAttributeStatusRecord)

Aggregations

ReadAttributeStatusRecord (com.zsmartsystems.zigbee.zcl.field.ReadAttributeStatusRecord)5 CommandTest (com.zsmartsystems.zigbee.CommandTest)3 DefaultDeserializer (com.zsmartsystems.zigbee.serialization.DefaultDeserializer)3 ZclFieldDeserializer (com.zsmartsystems.zigbee.zcl.ZclFieldDeserializer)3 Test (org.junit.Test)3 CommandResult (com.zsmartsystems.zigbee.CommandResult)1 ReadAttributesResponse (com.zsmartsystems.zigbee.zcl.clusters.general.ReadAttributesResponse)1 ExecutionException (java.util.concurrent.ExecutionException)1