Example #1
0
 private void handleEventType(State state, EcoTouchTags heatpumpCommandType) {
   for (EcoTouchBindingProvider provider : providers) {
     for (String itemName : provider.getItemNamesForType(heatpumpCommandType)) {
       eventPublisher.postUpdate(itemName, state);
     }
   }
 }
  /** @{inheritDoc */
  @Override
  protected void execute() {
    if (!bindingsExist()) {
      logger.debug("There is no existing EcoTouch binding configuration => refresh cycle aborted!");
      return;
    }
    try {
      // collect all tags which are actively used in items
      Set<String> tags = new HashSet<String>();
      for (EcoTouchBindingProvider provider : providers) {
        for (String tag : provider.getActiveTags()) {
          tags.add(tag);
        }
      }

      EcoTouchConnector connector = new EcoTouchConnector(ip, username, password, cookies);

      // collect raw values from heat pump
      HashMap<String, Integer> rawvalues = new HashMap<String, Integer>();

      // request values (this could later be handled more efficiently
      // inside connector.getValues(tags))
      for (String tag : tags) {
        try {
          int rawvalue = connector.getValue(tag); // raw value from
          // heat pump (needs
          // interpretation)
          rawvalues.put(tag, rawvalue);
        } catch (Exception e) {
          // the connector already logged the exception cause
          // let's ignore it and try the next value (intermittent
          // network problem?)
          continue;
        }
      }

      // post updates to event bus
      for (EcoTouchBindingProvider provider : providers) {
        for (EcoTouchTags item : provider.getActiveItems()) {
          if (!rawvalues.containsKey(item.getTagName())) {
            // could not get the value from the heat pump
            continue;
          }
          int heatpumpValue = rawvalues.get(item.getTagName());
          if (item.getType() == EcoTouchTags.Type.Analog) {
            // analog value encoded as a scaled integer
            BigDecimal decimal = new BigDecimal(heatpumpValue).divide(new BigDecimal(10));
            handleEventType(new DecimalType(decimal), item);
          } else if (item.getType() == EcoTouchTags.Type.Word) {
            // integer
            handleEventType(new DecimalType(heatpumpValue), item);
          } else {
            // bit field
            heatpumpValue >>= item.getBitNum();
            heatpumpValue &= 1;
            handleEventType(new DecimalType(heatpumpValue), item);
          }
        }
      }

      // store authentication info
      cookies = connector.getCookies();

    } finally {

    }
  }
Example #3
0
  @Override
  protected void internalReceiveCommand(String itemName, Command command) {
    // find the EcoTouch binding for the itemName
    EcoTouchTags tag = null;
    for (EcoTouchBindingProvider provider : providers) {
      try {
        tag = provider.getTypeForItemName(itemName);
        break;
      } catch (Exception e) {
      }
    }

    // consider special cases
    if (tag == EcoTouchTags.TYPE_ADAPT_HEATING) {
      double adapt = Double.parseDouble(command.toString());
      adapt = (adapt + 2) * 2;
      adapt = Math.max(0, adapt);
      adapt = Math.min(8, adapt);
      command = new DecimalType((int) adapt);
    }

    EcoTouchConnector connector = new EcoTouchConnector(ip, username, password, cookies);
    int value = 0;
    switch (tag.getType()) {
      case Analog:
        value = (int) (Double.parseDouble(command.toString()) * 10);
        break;
      case Word:
        if (command == OnOffType.ON) {
          value = 1;
        } else if (command == OnOffType.OFF) {
          value = 0;
        } else {
          value = Integer.parseInt(command.toString());
        }
        break;
      case Bitfield:
        try {
          // read-modify-write style
          value = connector.getValue(tag.getTagName());
          int bitmask = 1 << tag.getBitNum();
          if (command == OnOffType.OFF || Integer.parseInt(command.toString()) == 0) {
            value = value & ~bitmask;
          } else {
            value = value | bitmask;
          }
        } catch (Exception e1) {
          // connector.getValue() already logged a specific debug message
          logger.warn("cannot send command '" + command + "' to item '" + itemName + "'");
          return;
        }
    }

    try {
      connector.setValue(tag.getTagName(), value);
      // It does not make sense to check the returned value from
      // setValue().
      // Even if the tag is read only, one would get the newly set value
      // back.
    } catch (Exception e) {
      // connector.setValue() already logged a specific debug message
      logger.warn("cannot send command '" + command + "' to item '" + itemName + "'");
    }
  }