gpt4 book ai didi

com.zsmartsystems.zigbee.zcl.ZclAttribute类的使用及代码示例

转载 作者:知者 更新时间:2024-03-15 22:31:31 29 4
gpt4 key购买 nike

本文整理了Java中com.zsmartsystems.zigbee.zcl.ZclAttribute类的一些代码示例,展示了ZclAttribute类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZclAttribute类的具体详情如下:
包路径:com.zsmartsystems.zigbee.zcl.ZclAttribute
类名称:ZclAttribute

ZclAttribute介绍

[英]Defines a Cluster Library Attribute
[中]定义群集库属性

代码示例

代码示例来源:origin: zsmartsystems/com.zsmartsystems.zigbee

private void printAttributes(final ZclCluster cluster, final PrintStream out) {
    Map<Integer, ZclAttribute> attributeTree = new TreeMap<Integer, ZclAttribute>();
    for (ZclAttribute attribute : cluster.getAttributes()) {
      attributeTree.put(attribute.getId(), attribute);
    }

    for (ZclAttribute attribute : attributeTree.values()) {
      out.println(String.format("        %s   %5d %s%s%s %s %-40s %s %s",
          (cluster.getSupportedAttributes().contains(attribute.getId()) ? "S" : "U"), attribute.getId(),
          (attribute.isReadable() ? "r" : "-"), (attribute.isWritable() ? "w" : "-"),
          (attribute.isReportable() ? "s" : "-"), printZclDataType(attribute.getDataType()),
          attribute.getName(),
          (attribute.getLastValue() == null ? "" : attribute.getLastReportTime().getTime()),
          (attribute.getLastValue() == null ? "" : attribute.getLastValue())));
    }
  }
}

代码示例来源:origin: zsmartsystems/com.zsmartsystems.zigbee

protected Map<Integer, ZclAttribute> initializeAttributes() {
  Map<Integer, ZclAttribute> attributeMap = new ConcurrentHashMap<Integer, ZclAttribute>(8);
  attributeMap.put(ATTR_STATETEXT, new ZclAttribute(ZclClusterType.MULTISTATE_INPUT__BASIC, ATTR_STATETEXT, "StateText", ZclDataType.CHARACTER_STRING, false, true, true, false));
  attributeMap.put(ATTR_DESCRIPTION, new ZclAttribute(ZclClusterType.MULTISTATE_INPUT__BASIC, ATTR_DESCRIPTION, "Description", ZclDataType.CHARACTER_STRING, false, true, true, false));
  attributeMap.put(ATTR_NUMBEROFSTATES, new ZclAttribute(ZclClusterType.MULTISTATE_INPUT__BASIC, ATTR_NUMBEROFSTATES, "NumberOfStates", ZclDataType.UNSIGNED_16_BIT_INTEGER, true, true, true, false));
  attributeMap.put(ATTR_OUTOFSERVICE, new ZclAttribute(ZclClusterType.MULTISTATE_INPUT__BASIC, ATTR_OUTOFSERVICE, "OutOfService", ZclDataType.BOOLEAN, true, true, true, false));
  attributeMap.put(ATTR_PRESENTVALUE, new ZclAttribute(ZclClusterType.MULTISTATE_INPUT__BASIC, ATTR_PRESENTVALUE, "PresentValue", ZclDataType.UNSIGNED_16_BIT_INTEGER, true, true, true, false));
  attributeMap.put(ATTR_RELIABILITY, new ZclAttribute(ZclClusterType.MULTISTATE_INPUT__BASIC, ATTR_RELIABILITY, "Reliability", ZclDataType.ENUMERATION_8_BIT, false, true, true, false));
  attributeMap.put(ATTR_STATUSFLAGS, new ZclAttribute(ZclClusterType.MULTISTATE_INPUT__BASIC, ATTR_STATUSFLAGS, "StatusFlags", ZclDataType.BITMAP_8_BIT, true, true, false, false));
  attributeMap.put(ATTR_APPLICATIONTYPE, new ZclAttribute(ZclClusterType.MULTISTATE_INPUT__BASIC, ATTR_APPLICATIONTYPE, "ApplicationType", ZclDataType.SIGNED_32_BIT_INTEGER, false, true, false, false));
  return attributeMap;
}

代码示例来源:origin: openhab/org.openhab.binding.zigbee

@Override
public void attributeUpdated(ZclAttribute attribute) {
  logger.debug("{}: ZigBee attribute reports {}", endpoint.getIeeeAddress(), attribute);
  if (attribute.getCluster() == ZclClusterType.IAS_ZONE
      && attribute.getId() == ZclIasZoneCluster.ATTR_ZONESTATUS) {
    updateChannelState((Integer) attribute.getLastValue());
  }
}

代码示例来源:origin: zsmartsystems/com.zsmartsystems.zigbee

/**
 * Write an attribute
 *
 * @param attribute the {@link ZclAttribute} to write
 * @param value the value to set (as {@link Object})
 * @return command future {@link CommandResult}
 */
public Future<CommandResult> write(final ZclAttribute attribute, final Object value) {
  return write(attribute.getId(), attribute.getDataType(), value);
}

代码示例来源:origin: zsmartsystems/com.zsmartsystems.zigbee

/**
 * Synchronously get the <i>APSTxUcastRetry</i> attribute [attribute ID <b>266</b>].
 * <p>
 * This method can return cached data if the attribute has already been received.
 * The parameter <i>refreshPeriod</i> is used to control this. If the attribute has been received
 * within <i>refreshPeriod</i> milliseconds, then the method will immediately return the last value
 * received. If <i>refreshPeriod</i> is set to 0, then the attribute will always be updated.
 * <p>
 * This method will block until the response is received or a timeout occurs unless the current value is returned.
 * <p>
 * The attribute is of type {@link Integer}.
 * <p>
 * The implementation of this attribute by a device is MANDATORY
 *
 * @param refreshPeriod the maximum age of the data (in milliseconds) before an update is needed
 * @return the {@link Integer} attribute value, or null on error
 */
public Integer getApsTxUcastRetry(final long refreshPeriod) {
  if (attributes.get(ATTR_APSTXUCASTRETRY).isLastValueCurrent(refreshPeriod)) {
    return (Integer) attributes.get(ATTR_APSTXUCASTRETRY).getLastValue();
  }
  return (Integer) readSync(attributes.get(ATTR_APSTXUCASTRETRY));
}

代码示例来源:origin: zsmartsystems/com.zsmartsystems.zigbee

@Test
public void testConstructor() {
  ZclAttribute attribute = new ZclAttribute(ZclClusterType.ON_OFF, 0, "Test Name",
      ZclDataType.UNSIGNED_8_BIT_INTEGER, false, false, false, false);
  assertEquals(ZclClusterType.ON_OFF, attribute.getCluster());
  assertEquals(0, attribute.getId());
  assertEquals("Test Name", attribute.getName());
  assertEquals(ZclDataType.UNSIGNED_8_BIT_INTEGER, attribute.getDataType());
  assertEquals(false, attribute.isMandatory());
  assertEquals(false, attribute.isWritable());
  assertEquals(false, attribute.isReadable());
  assertEquals(false, attribute.isReportable());
  System.out.println(attribute.toString());
  attribute = new ZclAttribute(ZclClusterType.ON_OFF, 0, "Test Name", ZclDataType.UNSIGNED_8_BIT_INTEGER, true,
      true, true, true);
  assertEquals(true, attribute.isMandatory());
  assertEquals(true, attribute.isWritable());
  assertEquals(true, attribute.isReadable());
  assertEquals(true, attribute.isReportable());
  System.out.println(attribute.toString());
}

代码示例来源:origin: zsmartsystems/com.zsmartsystems.zigbee

@Test
  public void getLastReportTime() {
    ZclAttribute attribute = new ZclAttribute(ZclClusterType.ON_OFF, 0, "Test Name",
        ZclDataType.UNSIGNED_8_BIT_INTEGER, false, false, false, false);

    // No value has been set, so should always be false
    assertFalse(attribute.isLastValueCurrent(Long.MAX_VALUE));

    Calendar start = Calendar.getInstance();
    attribute.updateValue(0);
    Calendar stop = Calendar.getInstance();

    assertEquals(0, attribute.getLastValue());
    assertTrue(attribute.getLastReportTime().compareTo(start) >= 0);
    assertTrue(attribute.getLastReportTime().compareTo(stop) <= 0);

    try {
      Thread.sleep(100);
    } catch (InterruptedException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    assertFalse(attribute.isLastValueCurrent(50));
    assertTrue(attribute.isLastValueCurrent(Long.MAX_VALUE));
  }
}

代码示例来源:origin: zsmartsystems/com.zsmartsystems.zigbee

@Test
public void handleAttributeReport() {
  createEndpoint();
  ZclCluster cluster = new ZclOnOffCluster(endpoint);
  ZclAttributeListener listenerMock = Mockito.mock(ZclAttributeListener.class);
  ArgumentCaptor<ZclAttribute> attributeCapture = ArgumentCaptor.forClass(ZclAttribute.class);
  cluster.addAttributeListener(listenerMock);
  cluster.addAttributeListener(listenerMock);
  List<AttributeReport> attributeList = new ArrayList<AttributeReport>();
  AttributeReport report;
  report = new AttributeReport();
  report.setAttributeDataType(ZclDataType.SIGNED_8_BIT_INTEGER);
  report.setAttributeIdentifier(0);
  report.setAttributeValue(Integer.valueOf(1));
  System.out.println(report);
  attributeList.add(report);
  cluster.handleAttributeReport(attributeList);
  ZclAttribute attribute = cluster.getAttribute(0);
  assertTrue(attribute.getLastValue() instanceof Boolean);
  Mockito.verify(listenerMock, Mockito.timeout(1000).times(1)).attributeUpdated(attributeCapture.capture());
  attribute = attributeCapture.getValue();
  assertTrue(attribute.getLastValue() instanceof Boolean);
  assertEquals(ZclDataType.BOOLEAN, attribute.getDataType());
  assertEquals(0, attribute.getId());
  assertEquals(true, attribute.getLastValue());
  cluster.removeAttributeListener(listenerMock);
}

代码示例来源:origin: zsmartsystems/com.zsmartsystems.zigbee

/**
 * 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;
}

代码示例来源:origin: zsmartsystems/com.zsmartsystems.zigbee

private void updateAttribute(int attributeId, Object attributeValue) {
  ZclAttribute attribute = attributes.get(attributeId);
  if (attribute == null) {
    logger.debug("{}: Unknown attribute {} in cluster {}", zigbeeEndpoint.getEndpointAddress(), attributeId,
        clusterId);
  } else {
    attribute.updateValue(normalizer.normalizeZclData(attribute.getDataType(), attributeValue));
    notifyAttributeListener(attribute);
  }
}

代码示例来源:origin: zsmartsystems/com.zsmartsystems.zigbee

@Override
  public void process(ZigBeeNetworkManager networkManager, String[] args, PrintStream out)
      throws IllegalArgumentException, InterruptedException, ExecutionException {
    if (args.length != 3) {
      throw new IllegalArgumentException("Invalid number of arguments");
    }

    final ZigBeeEndpoint endpoint = getEndpoint(networkManager, args[1]);
    ZclCluster cluster = getCluster(endpoint, args[2]);

    final Future<Boolean> future = cluster.discoverAttributes(false);
    Boolean result = future.get();
    if (result) {
      out.println("Supported attributes for " + printCluster(cluster));
      out.println("AttrId  Data Type                  Name");
      for (Integer attributeId : cluster.getSupportedAttributes()) {
        out.print(" ");
        ZclAttribute attribute = cluster.getAttribute(attributeId);
        out.print(printAttributeId(attributeId));
        if (attribute != null) {
          out.print("  " + printZclDataType(attribute.getDataType()) + "  " + attribute.getName());
        }
        out.println();
      }
    } else {
      out.println("Failed to retrieve supported attributes");
    }
  }
}

代码示例来源:origin: zsmartsystems/com.zsmartsystems.zigbee

/**
 * Read an attribute
 *
 * @param attribute the {@link ZclAttribute} to read
 * @return command future
 */
public Future<CommandResult> read(final ZclAttribute attribute) {
  return read(attribute.getId());
}

代码示例来源:origin: zsmartsystems/com.zsmartsystems.zigbee

/**
 * Checks if the last value received for the attribute is still current.
 * If the last update time is more recent than the allowedAge then this will return true. allowedAge is defined in
 * milliseconds.
 *
 * @param allowedAge the number of milliseconds to consider the value current
 * @return true if the last value can be considered current
 */
public boolean isLastValueCurrent(long allowedAge) {
  if (lastReportTime == null) {
    return false;
  }
  long refreshTime = Calendar.getInstance().getTimeInMillis() - allowedAge;
  if (refreshTime < 0) {
    return true;
  }
  return getLastReportTime().getTimeInMillis() > refreshTime;
}

代码示例来源:origin: zsmartsystems/com.zsmartsystems.zigbee

attributeName = "Attribute " + attributeId;
} else {
  attributeName = attribute.getName();

代码示例来源:origin: zsmartsystems/com.zsmartsystems.zigbee

/**
 * Synchronously get the <i>NeighborStale</i> attribute [attribute ID <b>271</b>].
 * <p>
 * This method can return cached data if the attribute has already been received.
 * The parameter <i>refreshPeriod</i> is used to control this. If the attribute has been received
 * within <i>refreshPeriod</i> milliseconds, then the method will immediately return the last value
 * received. If <i>refreshPeriod</i> is set to 0, then the attribute will always be updated.
 * <p>
 * This method will block until the response is received or a timeout occurs unless the current value is returned.
 * <p>
 * The attribute is of type {@link Integer}.
 * <p>
 * The implementation of this attribute by a device is MANDATORY
 *
 * @param refreshPeriod the maximum age of the data (in milliseconds) before an update is needed
 * @return the {@link Integer} attribute value, or null on error
 */
public Integer getNeighborStale(final long refreshPeriod) {
  if (attributes.get(ATTR_NEIGHBORSTALE).isLastValueCurrent(refreshPeriod)) {
    return (Integer) attributes.get(ATTR_NEIGHBORSTALE).getLastValue();
  }
  return (Integer) readSync(attributes.get(ATTR_NEIGHBORSTALE));
}

代码示例来源:origin: zsmartsystems/com.zsmartsystems.zigbee

record.setAttributeIdentifier(attribute.getId());
record.setAttributeDataType(attribute.getDataType());
record.setMinimumReportingInterval(minInterval);
record.setMaximumReportingInterval(maxInterval);

代码示例来源:origin: zsmartsystems/com.zsmartsystems.zigbee

Object reportableChange = null;
if (args.length > 4) {
  reportableChange = parseValue(args[4], attribute.getDataType());

代码示例来源:origin: zsmartsystems/com.zsmartsystems.zigbee

/**
 * Gets the reporting configuration for an attribute
 *
 * @param attribute the {@link ZclAttribute} on which to enable reporting
 * @return command future {@link CommandResult}
 */
public Future<CommandResult> getReporting(final ZclAttribute attribute) {
  final ReadReportingConfigurationCommand command = new ReadReportingConfigurationCommand();
  command.setClusterId(clusterId);
  AttributeRecord record = new AttributeRecord();
  record.setAttributeIdentifier(attribute.getId());
  record.setDirection(0);
  command.setRecords(Collections.singletonList(record));
  command.setDestinationAddress(zigbeeEndpoint.getEndpointAddress());
  return send(command);
}

代码示例来源:origin: openhab/org.openhab.binding.zigbee

@Override
  public void attributeUpdated(ZclAttribute attribute) {
    logger.debug("{}: ZigBee attribute reports {}", endpoint.getIeeeAddress(), attribute);
    if (attribute.getCluster() == ZclClusterType.RELATIVE_HUMIDITY_MEASUREMENT
        && attribute.getId() == ZclRelativeHumidityMeasurementCluster.ATTR_MEASUREDVALUE) {
      Integer value = (Integer) attribute.getLastValue();
      if (value != null) {
        updateChannelState(new DecimalType(BigDecimal.valueOf(value, 2)));
      }
    }
  }
}

代码示例来源:origin: zsmartsystems/com.zsmartsystems.zigbee

/**
 * Synchronously get the <i>JoinIndication</i> attribute [attribute ID <b>272</b>].
 * <p>
 * This method can return cached data if the attribute has already been received.
 * The parameter <i>refreshPeriod</i> is used to control this. If the attribute has been received
 * within <i>refreshPeriod</i> milliseconds, then the method will immediately return the last value
 * received. If <i>refreshPeriod</i> is set to 0, then the attribute will always be updated.
 * <p>
 * This method will block until the response is received or a timeout occurs unless the current value is returned.
 * <p>
 * The attribute is of type {@link Integer}.
 * <p>
 * The implementation of this attribute by a device is MANDATORY
 *
 * @param refreshPeriod the maximum age of the data (in milliseconds) before an update is needed
 * @return the {@link Integer} attribute value, or null on error
 */
public Integer getJoinIndication(final long refreshPeriod) {
  if (attributes.get(ATTR_JOININDICATION).isLastValueCurrent(refreshPeriod)) {
    return (Integer) attributes.get(ATTR_JOININDICATION).getLastValue();
  }
  return (Integer) readSync(attributes.get(ATTR_JOININDICATION));
}

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com