Examples of HueBulb


Examples of org.openhab.binding.hue.internal.hardware.HueBulb

      // Get settings and update the bulbs
      // Observation : If the power of a hue lamp is removed, the status is not updated in hue hub.
      // The heartbeat functionality should fix this, but
      HueSettings settings = activeBridge.getSettings();
      for (int i = 1; i <= settings.getCount(); i++) {
        HueBulb bulb = bulbCache.get(i);
        if (bulb == null) {
          bulb = new HueBulb(activeBridge, i);
          bulbCache.put(i, bulb);
        }
        bulb.getStatus(settings);
      }
     
      // Update the items that are linked with the bulbs.
      // Multiple items of different types can be linked to one bulb.
      for (HueBindingProvider provider : this.providers) {
        for (String hueItemName : provider.getInBindingItemNames()) {
          HueBindingConfig deviceConfig = getConfigForItemName(hueItemName);
         
          if (deviceConfig != null) {
            HueBulb bulb = bulbCache.get(deviceConfig.getDeviceNumber());
            if (bulb != null) {
           
              // Enhancement: only send a postUpdate for items that have changed.
              // Tried to use item.getState() as found in enOcean binding, but the state value was always uninitialized
              // State actualState = provider.getItem(itemName).getState(); --> always return Uninitialized
              // Workaround for now, store the OnOff state in deviceConfig
              //
              if ((bulb.getIsOn() == true) && (bulb.getIsReachable() == true)) {
                if ((deviceConfig.itemStateOnOffType == null) || (deviceConfig.itemStateOnOffType.equals(OnOffType.ON) == false)) {
                  eventPublisher.postUpdate(hueItemName, OnOffType.ON);
                  deviceConfig.itemStateOnOffType = OnOffType.ON;
                }
              } else {
                if ((deviceConfig.itemStateOnOffType == null) || (deviceConfig.itemStateOnOffType.equals(OnOffType.OFF) == false)) {
                  eventPublisher.postUpdate(hueItemName, OnOffType.OFF);
                  deviceConfig.itemStateOnOffType = OnOffType.OFF;
                }
              }
             
              if (deviceConfig.getType().equals(BindingType.brightness)) {
                if ((bulb.getIsOn() == true) && (bulb.getIsReachable() == true)) {
                  // Only postUpdate when bulb is on, otherwise dimmer item is not retaining state and shows to max brightness value
                  PercentType newPercent = new PercentType((int)Math.round((bulb.getBrightness() * (double)100) / (double)255));
                  if ((deviceConfig.itemStatePercentType == null) || (deviceConfig.itemStatePercentType.equals(newPercent) == false)) {
                    eventPublisher.postUpdate(hueItemName, newPercent);
                    deviceConfig.itemStatePercentType = newPercent;
                  }
                }                 
              } else if (deviceConfig.getType().equals(BindingType.rgb)) {
                if ((bulb.getIsOn() == true) && (bulb.getIsReachable() == true)) {
                  // Only postUpdate when bulb is on, otherwise color item is not retaining state and shows to max brightness value
                  DecimalType decimalHue = new DecimalType(bulb.getHue() / (double)182);
                  PercentType percentBrightness = new PercentType((int)Math.round((bulb.getBrightness() * (double)100) / (double)255));
                  PercentType percentSaturation = new PercentType((int)Math.round((bulb.getSaturation() * (double)100) / (double)255));
                  HSBType newHsb = new HSBType(decimalHue, percentSaturation, percentBrightness);
                  if ((deviceConfig.itemStateHSBType == null) || (deviceConfig.itemStateHSBType.equals(newHsb) == false)) {
                    eventPublisher.postUpdate(hueItemName, newHsb);
                    deviceConfig.itemStateHSBType = newHsb;
                  }
View Full Code Here

Examples of org.openhab.binding.hue.internal.hardware.HueBulb

    if (deviceConfig == null) {
      return;
    }

    HueBulb bulb = bulbCache.get(deviceConfig.getDeviceNumber());
    if (bulb == null) {
      bulb = new HueBulb(bridge, deviceConfig.getDeviceNumber());
      bulbCache.put(deviceConfig.getDeviceNumber(), bulb);
    }

    if (command instanceof OnOffType) {
      bulb.switchOn(OnOffType.ON.equals(command));
    }

    if (command instanceof HSBType) {
      HSBType hsbCommand = (HSBType) command;
      DecimalType hue = hsbCommand.getHue();
      PercentType sat = hsbCommand.getSaturation();
      PercentType bri = hsbCommand.getBrightness();
      bulb.colorizeByHSB(hue.doubleValue() / 360,
          sat.doubleValue() / 100, bri.doubleValue() / 100);
    }

    if (deviceConfig.getType().equals(BindingType.brightness)
        || deviceConfig.getType().equals(BindingType.rgb)) {
      if (IncreaseDecreaseType.INCREASE.equals(command)) {
        int resultingValue = bulb.increaseBrightness(deviceConfig.getStepSize());
        eventPublisher.postUpdate(itemName, new PercentType(resultingValue));
      } else if (IncreaseDecreaseType.DECREASE.equals(command)) {
        int resultingValue = bulb.decreaseBrightness(deviceConfig.getStepSize());
        eventPublisher.postUpdate(itemName, new PercentType(resultingValue));
      } else if ((command instanceof PercentType) && !(command instanceof HSBType)) {
        bulb.setBrightness((int)Math.round((double)255 / (double)100 * ((PercentType) command).intValue()));
      }
    }

    if (deviceConfig.getType().equals(BindingType.colorTemperature)) {
      if (IncreaseDecreaseType.INCREASE.equals(command)) {
        bulb.increaseColorTemperature(deviceConfig.getStepSize());
      } else if (IncreaseDecreaseType.DECREASE.equals(command)) {
        bulb.decreaseColorTemperature(deviceConfig.getStepSize());
      } else if (command instanceof PercentType) {
        bulb.setColorTemperature((int)Math.round((((double)346 / (double)100) * ((PercentType) command).intValue()) + 154));
      }
    }

  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.