/*
Device lux range 0.1 - 40,000+ see
https://learn.adafruit.com/tsl2561/overview
354663
public double readLux() throws IOException {
        int ambient = readU16LittleEndian(TSL2561_COMMAND_BIT | TSL2561_REGISTER_CHAN0_LOW);
        int ir = readU16LittleEndian(TSL2561_COMMAND_BIT | TSL2561_REGISTER_CHAN1_LOW);

        if (ambient >= 0xffff || ir >= 0xffff) // value(s) exeed(s) datarange
            throw new RuntimeException("Gain too high. Values exceed range.");

        if (false && this.gain == TSL2561Gain.GAIN_1X) {
            ambient *= 16; // scale 1x to 16x
            ir *= 16; // scale 1x to 16x
        }
        double ratio = (ir / (float) ambient);

        LOG.debug("IR Result:" + ir);
        LOG.debug("Ambient Result:" + ambient);

        /*
         * For the values below, see
         * https://github.com/adafruit/Adafruit_TSL2561
         * /blob/master/Adafruit_TSL2561_U.h
         */
        double lux = 0d;
        if ((ratio >= 0) && (ratio <= TSL2561_LUX_K4C))
            lux = (TSL2561_LUX_B1C * ambient) - (0.0593 * ambient * (Math.pow(ratio, 1.4)));
        else if (ratio <= TSL2561_LUX_K5C)
            lux = (TSL2561_LUX_B5C * ambient) - (TSL2561_LUX_M5C * ir);
        else if (ratio <= TSL2561_LUX_K6C)
            lux = (TSL2561_LUX_B6C * ambient) - (TSL2561_LUX_M6C * ir);
        else if (ratio <= TSL2561_LUX_K7C)
            lux = (TSL2561_LUX_B7C * ambient) - (TSL2561_LUX_M7C * ir);
        else if (ratio > TSL2561_LUX_K8C)
            lux = 0;

        return lux;
    }
873187
def set_display_luminosity(self, luminosity):
        
        if (luminosity < 0) or (luminosity > 100):
            raise ValueError("Luminosity must be between 0 and 100")
        self.bbox_auth.set_access(BboxConstant.AUTHENTICATION_LEVEL_PRIVATE,
                                  BboxConstant.AUTHENTICATION_LEVEL_PRIVATE)
        self.bbox_url.set_api_name(BboxConstant.API_DEVICE, "display")
        data = {'luminosity': luminosity}
        api = BboxApiCall(self.bbox_url, BboxConstant.HTTP_METHOD_PUT, data,
                          self.bbox_auth)
        api.execute_api_request()
727136
def ambient_light_intensity(self):
        
        self._ensure_mode(self.MODE_AMBIENT)
        return self.value(0) * self._scale('AMBIENT')
609044
function(){
		var lightest,
			maxBrightness = Number.MIN_VALUE;
		this.each(function(c){
			var luma = c.luminance();
			if(luma > maxBrightness){
				lightest = c;
				maxBrightness = luma;
			}
		});
		return lightest;
	}
1028196
function enableLuxometerNotifications(device)
{
	// Turn Luxometer ON.
	device.writeCharacteristic(
		LUXOMETER_SERVICE,
		LUXOMETER_CONFIG,
		new Uint8Array([1]),
		turnOnLuxometerSuccess,
		turnOnLuxometerError)

	// Enable notifications from the Luxometer.
	device.enableNotification(
		LUXOMETER_SERVICE,
		LUXOMETER_DATA,
		readLuxometerSuccess,
		readLuxometerError)

	function turnOnLuxometerSuccess()
	{
		showMessage('Luxometer is ON')

	}
	function turnOnLuxometerError(error)
	{
		showMessage('Write Luxometer error: ' + error)
	}

	// Called repeatedly until disableNotification is called.
	function readLuxometerSuccess(data)
	{
		var lux = calculateLux(data)
		showMessage('Luxometer value: ' + lux)
	}

	function readLuxometerError(error)
	{
		showMessage('Read Luxometer error: ' + error)
	}
}
422720
private static int  hslToRgb(float hue, float sat, float light)
   {
      hue = (hue >= 0f) ? hue % 360f : (hue % 360f) + 360f;  // positive modulo (ie. -10 => 350)
      hue /= 60f;    // [0, 360] -> [0, 6]
      sat /= 100;   // [0, 100] -> [0, 1]
      light /= 100; // [0, 100] -> [0, 1]
      sat = (sat < 0f) ? 0f : (sat > 1f) ? 1f : sat;
      light = (light < 0f) ? 0f : (light > 1f) ? 1f : light;
      float  t1, t2;
      if (light <= 0.5f) {
         t2 = light * (sat + 1f);
      } else {
         t2 = light + sat - (light * sat);
      }
      t1 = light * 2f - t2;
      float  r = hueToRgb(t1, t2, hue + 2f);
      float  g = hueToRgb(t1, t2, hue);
      float  b = hueToRgb(t1, t2, hue - 2f);
      return clamp255(r * 256f)<<16 | clamp255(g * 256f)<<8 | clamp255(b * 256f);
   }
54019
def set_brightness(self, brightness):
        
        if not 25 <= brightness <= 255:
            raise ValueError("The brightness needs to be between 25 and 255.")

        payload = self.generate_payload(SET, {self.DPS_INDEX_BRIGHTNESS: brightness})
        data = self._send_receive(payload)
        return data
55312
def brightness_increment(increment = 1)
      params = { brightness: {} }
      params[:brightness][:increment] = increment
      @requester.put(url: "#{@api_url}/state", params: params)
    end
349984
function rgb2hcl(pixel) {
  const red = rgb2xyz(pixel[0]);
  const green = rgb2xyz(pixel[1]);
  const blue = rgb2xyz(pixel[2]);

  const x = xyz2lab(
    (0.4124564 * red + 0.3575761 * green + 0.1804375 * blue) / Xn);
  const y = xyz2lab(
    (0.2126729 * red + 0.7151522 * green + 0.0721750 * blue) / Yn);
  const z = xyz2lab(
    (0.0193339 * red + 0.1191920 * green + 0.9503041 * blue) / Zn);

  const l = 116 * y - 16;
  const a = 500 * (x - y);
  const b = 200 * (y - z);

  const c = Math.sqrt(a * a + b * b);
  let h = Math.atan2(b, a);
  if (h < 0) {
    h += twoPi;
  }

  pixel[0] = h;
  pixel[1] = c;
  pixel[2] = l;

  return pixel;
}
1196435
function calculateLuminance(hex, lum) {
  return Math.round(Math.min(Math.max(0, hex + (hex * lum)), 255));
}
606229
function Onvif() {
	// Public
	this.OnvifDevice = require('./modules/device.js');
	// Private
	this._OnvifSoap  = require('./modules/soap.js');
	this._MULTICAST_ADDRESS = '239.255.255.250';
	this._PORT = 3702;
	this._udp = null;
	this._devices = {};
	this._DISCOVERY_INTERVAL = 150; // ms
	this._DISCOVERY_RETRY_MAX = 3;
	this._DISCOVERY_WAIT = 3000; // ms
	this._discovery_interval_timer = null;
	this._discovery_wait_timer = null;
}
1113940
def prox_max(X, step, thresh=0):
    
    thresh_ = _step_gamma(step, thresh)
    above = X - thresh_ > 0
    X[above] = thresh_
    return X
1330851
def set_hsb(self, hue, saturation, brightness=None, *, index=0,
                transition_time=None):
        """"""
        self._value_validate(hue, RANGE_HUE, "Hue")
        self._value_validate(saturation, RANGE_SATURATION, "Saturation")

        values = {
            ATTR_LIGHT_COLOR_SATURATION: saturation,
            ATTR_LIGHT_COLOR_HUE: hue
        }

        if brightness is not None:
            values[ATTR_LIGHT_DIMMER] = brightness
            self._value_validate(brightness, RANGE_BRIGHTNESS, "Brightness")

        if transition_time is not None:
            values[ATTR_TRANSITION_TIME] = transition_time

        return self.set_values(values, index=index)
1146308
function computeStrip(scrollSize, clientSize) {
      // const container = this.$refs.stripContainer // 滚动条的容器
      var currentSize = this.$refs.stripContainer[this.config.client];
      /**
       * 滚动条长度。
       *
       * clientSize / scrollSize 是表示视图范围与用户内容元素的比例
       * 用此比例来决定 滚动条的长度 滚动条容器 * 比例 = 滚动条长度
       * 但是当用户内容元素无限大的时候，可能会导致滚动条无限小，所以会设置最小长度
       */
      this.length = currentSize * (clientSize / scrollSize);
      var minLength = this.horizontal ? this.minLengthH : this.minLengthV;
      if (minLength < 1) {
        // 按百分比处理
        minLength = currentSize * minLength;
      }
      // 判断是否滚动条长度是否已经小于了设置的最小长度
      this.length = this.length < minLength ? minLength : this.length;
      // 滚动条容器 - 滚动条长度 = 剩余的空间
      var space = this.maxOffset = currentSize - this.length;
      /**
       * 这里计算一个比例
       * 已高度举例子:
       * 使用 剩余空间 除以 (用户内容元素的高度 - 视图区域的高度)
       * 可以把 视图区域的高度 比作 滚动条的长度 用户内容元素的高度 比作 滚动条容器的高度
       * 所以使用两者剩余空间的比例，来计算 当滚动条滑动1px的时候 用户内容元素应该滑动多少 px，当用户内容元素移动时 来计算 滚动条应该移动多少px
       */
      this.percentage = space / (scrollSize - clientSize);
    }
625899
def set_night_light_brightness(self, brightness=200):
        """"""
        self.publish(
            action='set',
            resource='cameras/{}'.format(self.device_id),
            publish_response=False,
            properties={'nightLight': {'brightness': brightness}}
        )
319799
function( c ){
            var isInRange = this.isValueInConstraint(c.hue(), this.hueConstraint);
            isInRange &= this.isValueInConstraint(c.saturation(), this.saturationConstraint);
            isInRange &= this.isValueInConstraint(c.brightness(), this.brightnessConstraint);
            isInRange &= this.isValueInConstraint(c.alpha(), this.alphaConstraint);
            return isInRange || false; //if its 0, return false
        }
1154037
function adjustBrightness($hex, $steps)
    {
        // Steps should be between -255 and 255. Negative = darker, positive = lighter
        $steps = max(-255, min(255, $steps));

        // Normalize into a six character long hex string
        $hex = str_replace('#', '', $hex);
        if (strlen($hex) == 3) {
            $hex = str_repeat(substr($hex, 0, 1), 2) . str_repeat(substr($hex, 1, 1), 2) . str_repeat(substr($hex, 2, 1), 2);
        }

        // Split into three parts: R, G and B
        $color_parts = str_split($hex, 2);
        $return = '#';

        foreach ($color_parts as $color) {
            $color = hexdec($color); // Convert to decimal
            $color = max(0, min(255, $color + $steps)); // Adjust color
            $return .= str_pad(dechex($color), 2, '0', STR_PAD_LEFT); // Make two char hex code
        }

        return $return;
    }