Beispiel #1
0
        /**
         * The groupIndex given here is the same groupIndex the Hue knows about.
         */
        public void SendGroupCommand(int groupIndex, HueCommand command)
        {
            string url = this.config.hueURL + "groups/" + groupIndex + "/action/";

            this.buffer.Enqueue(new HueMessage()
            {
                command = command,
                uri     = new Uri(url),
            });
        }
Beispiel #2
0
        /**
         * Note: the lightIndex given here is local, and is mapped to the actual
         * index the Hue uses through this.config.hueIndices.
         */
        public void SendLightCommand(int lightIndex, HueCommand command)
        {
            string url = this.config.hueURL
                         + "lights/"
                         + this.config.hueIndices[lightIndex]
                         + "/state/";
            string message = command.ToJson();

            this.buffer.Enqueue(new HueMessage()
            {
                command = command,
                uri     = new Uri(url),
            });
        }
Beispiel #3
0
 /**
  * Note: the lightIndex given here is local, and is mapped to the actual
  * index the Hue uses through this.config.hueIndices.
  */
 public void SendLightCommand(int lightIndex, HueCommand command)
 {
     string url = this.config.hueURL
     + "lights/"
     + this.config.hueIndices[lightIndex]
     + "/state/";
       string message = command.ToJson();
       this.buffer.Enqueue(new HueMessage() {
     command = command,
     uri = new Uri(url),
       });
 }
Beispiel #4
0
 /**
  * The groupIndex given here is the same groupIndex the Hue knows about.
  */
 public void SendGroupCommand(int groupIndex, HueCommand command)
 {
     string url = this.config.hueURL + "groups/" + groupIndex + "/action/";
       this.buffer.Enqueue(new HueMessage() {
     command = command,
     uri = new Uri(url),
       });
 }
        public void Visualize()
        {
            bool shouldUpdate = false;
              if (
            this.lastControlLights != this.config.controlLights ||
            this.lastLightsOff != this.config.lightsOff ||
            this.lastRedAlert != this.config.redAlert ||
            this.lastBrighten != this.config.brighten ||
            this.lastSat != this.config.sat ||
            this.lastColorslide != this.config.colorslide
              ) {
            this.lastControlLights = this.config.controlLights;
            this.lastLightsOff = this.config.lightsOff;
            this.lastRedAlert = this.config.redAlert;
            this.lastBrighten = this.config.brighten;
            this.lastSat = this.config.sat;
            this.lastColorslide = this.config.colorslide;
            shouldUpdate = true;
              }

              if (!this.shouldRun && !shouldUpdate) {
            return;
              }

              HueCommand command;
              if (this.config.lightsOff) {
            command = new HueCommand() {
              on = false,
            };
              } else if (this.config.redAlert) {
            command = new HueCommand() {
              on = true,
              bri = 1,
              hue = 1,
              sat = 254,
              effect = "none",
            };
              } else {
            int newbri = Math.Min(Math.Max(254 + 64 * this.config.brighten, 1), 254);
            int newsat = Math.Min(Math.Max(126 + 63 * this.config.sat, 0), 254);
            int newhue = Math.Min(Math.Max(16384 + this.config.colorslide * 4096, 0), 65535);
            command = new HueCommand() {
              on = true,
              bri = newbri,
              hue = newhue,
              sat = newsat,
              effect = "none",
            };
              }

              // We need to spam a bunch of these commands because the Hue hub sucks and
              // executes commands we give it out-of-order
              int timesToRun = this.shouldRun ? 15 : 1;
              for (int i = 0; i < timesToRun; i++) {
            for (int j = 0; j < this.config.hueIndices.Length; j++) {
              this.hue.SendLightCommand(j, command);
            }
              }

              this.shouldRun = false;
        }