コード例 #1
0
  /**
   * Find the first matching {@link OpenSprinklerBindingProvider} according to <code>itemName</code>
   * and <code>command</code>.
   *
   * @param itemName
   * @param command
   * @return the matching binding provider or <code>null</code> if no binding provider could be
   *     found
   */
  private OpenSprinklerBindingProvider findFirstMatchingBindingProvider(
      String itemName, Command command) {
    OpenSprinklerBindingProvider firstMatchingProvider = null;

    for (OpenSprinklerBindingProvider provider : this.providers) {
      boolean match = provider.providesBindingFor(itemName);
      if (match) {
        firstMatchingProvider = provider;
        break;
      }
    }

    return firstMatchingProvider;
  }
コード例 #2
0
  /**
   * Find the first matching provider name according to <code>stationValue</code>.
   *
   * @param stationValue
   * @return the matching binding provider or <code>null</code> if no binding provider could be
   *     found
   */
  private String findFirstMatchingItemName(int stationValue) {
    String firstMatchingName = null;

    for (OpenSprinklerBindingProvider provider : this.providers) {
      for (String itemName : provider.getItemNames()) {
        boolean match = (provider.getStationNumber(itemName) == stationValue);

        if (match) {
          firstMatchingName = itemName;
          break;
        }
      }
    }

    return firstMatchingName;
  }
コード例 #3
0
  /**
   * Find the first matching provider name according to <code>commandValue</code>.
   *
   * @param commandValue
   * @return the matching binding provider or <code>null</code> if no binding provider could be
   *     found
   */
  private String findFirstMatchingItemName(String commandValue) {
    String firstMatchingName = null;

    for (OpenSprinklerBindingProvider provider : this.providers) {
      for (String itemName : provider.getItemNames()) {
        boolean match = provider.getCommand(itemName).equals(commandValue);

        if (match) {
          firstMatchingName = itemName;
          break;
        }
      }
    }

    return firstMatchingName;
  }
コード例 #4
0
  /** @{inheritDoc} */
  @Override
  protected void internalReceiveCommand(String itemName, Command command) {
    // the code being executed when a command was sent on the openHAB
    // event bus goes here. This method is only called if one of the
    // BindingProviders provide a binding for the given 'itemName'.

    if (command instanceof OnOffType) {
      final OnOffType switchCommand = (OnOffType) command;
      final OpenSprinklerBindingProvider bindingProvider =
          findFirstMatchingBindingProvider(itemName, command);
      final int station = bindingProvider.getStationNumber(itemName);

      if (station < 0 || station >= numberOfStations) {
        logger.warn(
            "Station "
                + station
                + " is not in the valid ["
                + 0
                + ".."
                + numberOfStations
                + "] range");
        return;
      }

      switch (switchCommand) {
        case ON:
          openSprinkler.openStation(station);
          break;
        case OFF:
          openSprinkler.closeStation(station);
          break;
      }

      return;
    }

    if (command instanceof OpenClosedType) {
      // abort processing
      return;
    }

    logger.debug("Provided command " + command + " is not of type 'OnOffType' or 'OpenClosedType'");
  }