Package org.openhab.core.library.types

Examples of org.openhab.core.library.types.PercentType


        command.append(UP_BYTE);
      } else if (channelState.equals(UpDownType.DOWN)) {
        command.append(DOWN_BYTE);
      } else if (channelState instanceof PercentType){
        // calculate dimmer value...
        PercentType currentState = (PercentType) channelState;
        int value = BigDecimal.valueOf(255).multiply(currentState.toBigDecimal()).divide(BigDecimal.valueOf(100), 0,
            BigDecimal.ROUND_UP).intValue();
        command.append(StringUtils.leftPad(Integer.toHexString(value), 2, "0").toUpperCase());
      } else {
        command.append(HIGH_BYTE);
      }
View Full Code Here


      }
      State currentState = channels[i].getState();
      String newValue = command.substring(9 + (i * 2), 11 + (i * 2));
     
      if (channels[i].supportsPercentType()) {         
        PercentType value = getPercentTypeFromByteString(newValue);         
        if (!currentState.equals(value)) {
          binding.postUpdate(channels[i].getName(), value);
          channels[i].setState(value);
       
      } else {
View Full Code Here

   * Convert a 0-FF scale value to a percent type.
   */
  private PercentType getPercentTypeFromByteString(String byteValue) {
   
    long value = Long.parseLong(byteValue, 16);
    return new PercentType(BigDecimal
        .valueOf(value)
        .multiply(BigDecimal.valueOf(100))
        .divide(BigDecimal.valueOf(255), 0,
            BigDecimal.ROUND_UP).intValue());
  }
View Full Code Here

          index = convertVolumeToPercent( Integer.parseInt(payloadSubstring) );
        }
        else {
          index = Integer.parseInt(payloadSubstring);
        }
        state = new PercentType(index);
       
      } else if (itemType == NumberItem.class) {
          index = Integer.parseInt(payloadSubstring);
          state = new DecimalType(index);
       
      } else if (itemType == RollershutterItem.class) {
        index = Integer.parseInt(payloadSubstring);
        state = new PercentType(index);
       
      } else if (itemType == StringItem.class) {
        state = new StringType(payloadSubstring);
      }
    } catch (Exception e) {
View Full Code Here

          sendOff(bulb, bridgeId);
        }
        if (IncreaseDecreaseType.INCREASE.equals(command)) {
          sendOn(bulb, bridgeId);
          Thread.sleep(100);
          PercentType newValue = sendIncrease(bulb, rgbwSteps, bridgeId);
          eventPublisher.postUpdate(itemName, newValue);
        } else if (IncreaseDecreaseType.DECREASE.equals(command)) {
          PercentType newValue = sendDecrease(bulb, rgbwSteps, bridgeId);
          eventPublisher.postUpdate(itemName, newValue);
        } else if (command instanceof PercentType) {
          logger.debug("milight: command is of type PercentType");
          sendPercent(bulb, rgbwSteps, bridgeId, (PercentType) command, BindingType.brightness);
        }
      }
      else if (deviceConfig.getCommandType().equals(BindingType.nightMode)) {
        logger.debug("milight: item is of type nightMode");
        if (OnOffType.ON.equals(command)) {
          sendNightMode(bulb, bridgeId);
        }
        if (OnOffType.OFF.equals(command)) {
          sendOff(bulb, bridgeId);
        }

      }
      else if (deviceConfig.getCommandType().equals(BindingType.whiteMode)) {
        logger.debug("milight: item is of type whiteMode");
        if (OnOffType.ON.equals(command)) {
          sendOn(bulb, bridgeId);
          Thread.sleep(100);
          sendWhiteMode(bulb, bridgeId);
        }
        if (OnOffType.OFF.equals(command)) {
          sendOff(bulb, bridgeId);
        }

      }
      else if (deviceConfig.getCommandType().equals(BindingType.colorTemperature)) {
        logger.debug("milight: item is of type warm/cold white");
        if (OnOffType.ON.equals(command)) {
          sendPercent(bulb, rgbwSteps, bridgeId, PercentType.HUNDRED, BindingType.colorTemperature);
        } else if (OnOffType.OFF.equals(command)) {
          sendPercent(bulb, rgbwSteps, bridgeId, PercentType.ZERO, BindingType.colorTemperature);
        } else if (IncreaseDecreaseType.INCREASE.equals(command)) {
          PercentType newValue = sendWarmer(bulb, bridgeId);
          eventPublisher.postUpdate(itemName, newValue);
        } else if (IncreaseDecreaseType.DECREASE.equals(command)) {
          PercentType newValue = sendCooler(bulb, bridgeId);
          eventPublisher.postUpdate(itemName, newValue);
        } else if (command instanceof PercentType) {
          sendPercent(bulb, rgbwSteps, bridgeId, (PercentType) command, BindingType.colorTemperature);
        }
      }
View Full Code Here

    }
    if(BindingType.brightness.equals(type) && command.equals(PercentType.HUNDRED)) {
      sendFull(bulb, rgbwSteps, bridgeId);
      return;
    }
    PercentType oldPercent = getCurrentState(bulb, bridgeId, type);
    if(oldPercent.equals(PercentType.ZERO)) sendOn(bulb, bridgeId);
    try {
      if (bulb < 6) {
        if (command.compareTo(oldPercent) > 0) {
          int repeatCount = (command.intValue() - oldPercent.intValue()) / 10;
          for(int i = 0; i <= repeatCount; i++) {
            Thread.sleep(100);
            if(BindingType.brightness.equals(type) && bulb < 6) {
              sendIncrease(bulb, rgbwSteps, bridgeId);
            } else if(BindingType.colorTemperature.equals(type)) {
              sendWarmer(bulb, bridgeId);
            } else if(BindingType.discoSpeed.equals(type)) {

              sendIncreaseSpeed(bulb, bridgeId);
            } else if(BindingType.discoMode.equals(type)) {
              sendDiscoModeUp(bulb, bridgeId);
            }
          }
        } else if (command.compareTo(oldPercent) < 0) {
          int repeatCount = (oldPercent.intValue() - command.intValue()) / 10;
          for(int i = 0; i <= repeatCount; i++) {
            Thread.sleep(100);
            if(BindingType.brightness.equals(type) && bulb < 6) {
              sendDecrease(bulb, rgbwSteps, bridgeId);
            } else if(BindingType.colorTemperature.equals(type)) {
View Full Code Here

      logger.debug("Sleeping thread has been interrupted.");
    }
  }

  private PercentType getCurrentState(int bulb, String bridgeId, BindingType type) {
    PercentType percent = dimmerState.get(bridgeId + bulb + type);
    if(percent == null) {
      percent = PercentType.ZERO;
    }
    return percent;
  }
View Full Code Here

    }
    int newPercent = currentPercent + 10;
    if(newPercent > 100) {
      newPercent = 100;
    }
    PercentType newValue = new PercentType(newPercent);
    if (bulb > 5) {
      int increasePercent = newPercent * rgbwSteps / 100;
      messageBytes = "4E:" + Integer.toHexString(increasePercent) + ":55";
      logger.debug("Bulb '{}' set to '{}' dimming Steps", bulb, rgbwSteps);
    }
View Full Code Here

    }
    int newPercent = getCurrentState(bulb, bridgeId, BindingType.brightness).intValue() - 10;
    if(newPercent < 0) {
      newPercent = 0;
    }
    PercentType newValue = new PercentType(newPercent);
    if(newValue.equals(PercentType.ZERO)) {
      sendOff(bulb, bridgeId);
    } else {
      if (bulb > 5) {
        int decreasePercent = newPercent * rgbwSteps / 100;
        messageBytes = "4E:" + Integer.toHexString(decreasePercent) + ":55";
View Full Code Here

    logger.debug("milight: sendWarmer");
    int newPercent = getCurrentState(bulb, bridgeId, BindingType.brightness).intValue() + 10;
    if(newPercent > 100) {
      newPercent = 100;
    }
    PercentType newValue = new PercentType(newPercent);
    String messageBytes = "3E:00:55";
    sendMessage(messageBytes, bridgeId);
    setCurrentState(bulb, bridgeId, newValue, BindingType.brightness);
    return newValue;
  }
View Full Code Here

TOP

Related Classes of org.openhab.core.library.types.PercentType

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.