/**
   * Handles an incoming {@link ZWaveCommandClassValueEvent}. Implement this message in derived
   * classes to convert the value and post an update on the openHAB bus.
   *
   * @param provider the {@link ZWaveBindingProvider} that provides the item
   * @param itemName the name of the item that will receive the event.
   * @param event the received {@link ZWaveCommandClassValueEvent}.
   */
  public void handleEvent(
      ZWaveBindingProvider provider, String itemName, ZWaveCommandClassValueEvent event) {
    ZWaveBindingConfig bindingConfiguration = provider.getZwaveBindingConfig(itemName);
    Item item = provider.getItem(itemName);
    String commandClassName = bindingConfiguration.getArguments().get("command");
    boolean respondToBasic =
        "true".equalsIgnoreCase(bindingConfiguration.getArguments().get("respond_to_basic"));

    logger.trace(
        "Getting converter for item = {}, command class = {}, item command class = {}",
        itemName,
        event.getCommandClass().getLabel(),
        commandClassName);

    if (item == null) return;

    // check whether this item is bound to the right command class.

    if (commandClassName != null
        && !commandClassName.equalsIgnoreCase(event.getCommandClass().getLabel().toLowerCase())
        && !(respondToBasic && event.getCommandClass() == CommandClass.BASIC)) return;

    ZWaveCommandClassConverter<?> converter = this.getConverter(event.getCommandClass());

    if (converter == null) {
      logger.warn(
          "No converter found for command class = {}, ignoring event.",
          event.getCommandClass().toString());
      return;
    }

    converter.handleEvent(event, item, bindingConfiguration.getArguments());
  }
  /** {@inheritDoc} */
  @Override
  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;
    }

    State state = converter.convertFromValueToState(event.getValue());
    this.getEventPublisher().postUpdate(item.getName(), state);
  }
  /** {@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);
  }
Exemplo n.º 4
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);
  }