/** {@inheritDoc} */
  @Override
  public State handleEvent(ZWaveThingChannel channel, ZWaveCommandClassValueEvent event) {
    // We ignore any meter reports for item bindings configured with 'reset=true'
    // since we don't want to be updating the 'reset' switch
    if ("true".equalsIgnoreCase(channel.getArguments().get("reset"))) {
      return null;
    }

    String meterScale = channel.getArguments().get("type");
    String meterZero = channel.getArguments().get("zero"); // needs to be a config setting - not arg
    ZWaveMeterValueEvent meterEvent = (ZWaveMeterValueEvent) event;
    // logger.debug("Meter converter: scale {} <> {}", meterScale, meterEvent.getMeterScale());

    // Don't trigger event if this item is bound to another sensor type
    if (meterScale != null && MeterScale.getMeterScale(meterScale) != meterEvent.getMeterScale()) {
      logger.debug("Not the right scale {} <> {}", meterScale, meterEvent.getMeterScale());
      return null;
    }

    BigDecimal val = (BigDecimal) event.getValue();

    // If we've set a zero, then anything below this value needs to be considered ZERO
    if (meterZero != null) {
      if (val.doubleValue() <= Double.parseDouble(meterZero)) {
        val = BigDecimal.ZERO;
      }
    }

    return new DecimalType(val);
  }
  /** {@inheritDoc} */
  @Override
  public List<SerialMessage> executeRefresh(ZWaveThingChannel channel, ZWaveNode node) {
    ZWaveMeterCommandClass commandClass =
        (ZWaveMeterCommandClass)
            node.resolveCommandClass(ZWaveCommandClass.CommandClass.METER, channel.getEndpoint());
    if (commandClass == null) {
      return null;
    }

    logger.debug(
        "NODE {}: Generating poll message for {}, endpoint {}",
        node.getNodeId(),
        commandClass.getCommandClass().getLabel(),
        channel.getEndpoint());
    SerialMessage serialMessage;

    // Don't refresh channels that are the reset button
    if ("true".equalsIgnoreCase(channel.getArguments().get("reset"))) {
      return null;
    }

    String meterScale = channel.getArguments().get("type");
    logger.debug(
        "NODE {}: Generating poll message for {}, endpoint {}",
        node.getNodeId(),
        commandClass.getCommandClass().getLabel(),
        channel.getEndpoint());

    if (meterScale != null) {
      serialMessage =
          node.encapsulate(
              commandClass.getMessage(MeterScale.getMeterScale(meterScale)),
              commandClass,
              channel.getEndpoint());
    } else {
      serialMessage =
          node.encapsulate(commandClass.getValueMessage(), commandClass, channel.getEndpoint());
    }

    List<SerialMessage> response = new ArrayList<SerialMessage>(1);
    response.add(serialMessage);
    return response;
  }
Exemplo n.º 3
0
  /** {@inheritDoc} */
  @Override
  public void handleEvent(
      ZWaveCommandClassValueEvent event, Item item, Map<String, String> arguments) {
    ZWaveStateConverter<?, ?> converter = this.getStateConverter(item, event.getValue());

    if (converter == null) {
      logger.warn(
          "NODE {}: No converter found for item = {}, endpoint = {}, ignoring event.",
          event.getNodeId(),
          item.getName(),
          event.getEndpoint());
      return;
    }

    // we ignore any meter reports for item bindings configured with 'meter_reset=true'
    // since we don't want to be updating the 'reset' switch
    if ("true".equalsIgnoreCase(arguments.get("meter_reset"))) {
      return;
    }

    String meterScale = arguments.get("meter_scale");
    String meterZero = arguments.get("meter_zero");
    ZWaveMeterValueEvent meterEvent = (ZWaveMeterValueEvent) event;

    // Don't trigger event if this item is bound to another sensor type
    if (meterScale != null && MeterScale.getMeterScale(meterScale) != meterEvent.getMeterScale()) {
      return;
    }

    Object val = event.getValue();

    // If we've set a zero, then anything below this value needs to be considered ZERO
    if (meterZero != null) {
      if (((BigDecimal) val).doubleValue() <= Double.parseDouble(meterZero)) {
        val = BigDecimal.ZERO;
      }
    }

    State state = converter.convertFromValueToState(val);
    this.getEventPublisher().postUpdate(item.getName(), state);
  }
Exemplo n.º 4
0
  /** {@inheritDoc} */
  @Override
  public SerialMessage executeRefresh(
      ZWaveNode node,
      ZWaveMeterCommandClass commandClass,
      int endpointId,
      Map<String, String> arguments) {
    String meterScale = arguments.get("meter_scale");

    logger.debug(
        "NODE {}: Generating poll message for {}, endpoint {}",
        node.getNodeId(),
        commandClass.getCommandClass().getLabel(),
        endpointId);

    if (meterScale != null) {
      return node.encapsulate(
          commandClass.getMessage(MeterScale.getMeterScale(meterScale)), commandClass, endpointId);
    } else {
      return node.encapsulate(commandClass.getValueMessage(), commandClass, endpointId);
    }
  }