Пример #1
0
  public LightDevice() throws InvalidDescriptionException {
    super(new File(DESCRIPTION_FILE_NAME));
    setSSDPBindAddress(HostInterface.getInetAddress(HostInterface.IPV4_BITMASK, null));
    setHTTPBindAddress(HostInterface.getInetAddress(HostInterface.IPV4_BITMASK, null));

    Action getPowerAction = getAction("GetPower");
    getPowerAction.setActionListener(this);

    Action setPowerAction = getAction("SetPower");
    setPowerAction.setActionListener(this);

    ServiceList serviceList = getServiceList();
    Service service = serviceList.getService(0);
    service.setQueryListener(this);

    powerVar = getStateVariable("Power");

    Argument powerArg = getPowerAction.getArgument("Power");
    StateVariable powerState = powerArg.getRelatedStateVariable();
    AllowedValueList allowList = powerState.getAllowedValueList();
    for (int n = 0; n < allowList.size(); n++)
      System.out.println("[" + n + "] = " + allowList.getAllowedValue(n));

    AllowedValueRange allowRange = powerState.getAllowedValueRange();
    System.out.println("maximum = " + allowRange.getMaximum());
    System.out.println("minimum = " + allowRange.getMinimum());
    System.out.println("step = " + allowRange.getStep());
  }
  /**
   * @param allowedValueRange
   * @since 0.3
   */
  private void initMaxMinStep(AllowedValueRange allowedValueRange) {
    // PRE:invoked only by initValueConstraint() thus allowedValueRange must not  be null
    if (allowedValueRange == null) {
      return;
    }

    if (!Number.class.isAssignableFrom(getJavaDataType())) {
      Activator.logger.WARNING(
          "Imported device with StateVariable "
              + variable.getName()
              + " contains AllowedValueRange but its UPnP type doesn't allow it because it is +"
              + getUPnPDataType());
      return;
    }

    final String maxStr = allowedValueRange.getMaximum();
    final String minStr = allowedValueRange.getMinimum();
    final String stepStr = allowedValueRange.getStep();

    try {
      final String type = getUPnPDataType();
      max = (Number) Converter.parseString(maxStr, type);
      min = (Number) Converter.parseString(minStr, type);
      step = (Number) Converter.parseString(stepStr, type);
    } catch (Exception ex) {
      Activator.logger.WARNING(
          "Imported device with StateVariable "
              + variable.getName()
              + " contains an invalid definition for AllowedValueRange");
    }
    hasMaxMinStep = Boolean.TRUE;
  }