コード例 #1
0
        public void MYLIGHTHANDLER(object __sender__ /*HueLights.HueLight SENDER */, EventArgs ARGS)
        {
            HueLight SENDER = (HueLight )__sender__;

            try
            {
                SplusExecutionContext __context__ = SplusSimplSharpDelegateThreadStartCode();

                __context__.SourceCodeLine = 114;
                if (Functions.TestForTrue((MYLIGHT.Reachable)))
                {
                    __context__.SourceCodeLine = 116;
                    LOADONLINE.Value           = (ushort)(MYLIGHT.BulbOnline);
                    __context__.SourceCodeLine = 117;
                    LOADISON.Value             = (ushort)(MYLIGHT.BulbIsOn);
                    __context__.SourceCodeLine = 118;
                    LIGHTTYPE.UpdateValue(MYLIGHT.BulbType);
                    __context__.SourceCodeLine = 119;
                    BRIOUT.Value = (ushort)(MYLIGHT.BulbBri);
                    __context__.SourceCodeLine = 120;
                    LOADREACHABLE.Value        = (ushort)(MYLIGHT.Reachable);
                    __context__.SourceCodeLine = 121;
                    HUEOUT.Value = (ushort)(MYLIGHT.BulbHue);
                    __context__.SourceCodeLine = 122;
                    SATOUT.Value = (ushort)(MYLIGHT.BulbSat);
                }
            }
            finally { ObjectFinallyHandler(); }
        }
コード例 #2
0
        internal int AddHueLight(HueLight light, HueBridgeNode node)
        {
            var lightNr = _driver.AddLight(light);

            _hueBridgeMapping.Add(light.Id, node);
            return(lightNr);
        }
コード例 #3
0
ファイル: HueConnector.cs プロジェクト: magico13/HomeAPI
        /// <inheritdoc/>
        public async Task <List <HueLight> > GetLightsAsync()
        {
            if (credentials == null)
            {
                throw new UnauthorizedAccessException(UNCONFIGURED_EXCEPTION);
            }
            string          url    = credentials.APIURL + "lights";
            List <HueLight> lights = new List <HueLight>();

            try
            {
                HttpResponseMessage response = await _client.GetAsync(url);

                if (response.IsSuccessStatusCode)
                {
                    string content = await response.Content.ReadAsStringAsync();

                    JObject obj = JObject.Parse(content);
                    //list of lights with the id and then all the data
                    foreach (KeyValuePair <string, JToken> lightKVP in obj)
                    {
                        HueLight light = lightKVP.Value.ToObject <HueLight>();
                        light.ID = long.Parse(lightKVP.Key);
                        lights.Add(light);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(lights);
        }
コード例 #4
0
 public bool Equals(HueLight obj)
 {
     if (!Id.Equals(obj.Id))
     {
         return(false);
     }
     if (!Name.Equals(obj.Name))
     {
         return(false);
     }
     if (!IsReachable.Equals(obj.IsReachable))
     {
         return(false);
     }
     if (!IsOn.Equals(obj.IsOn))
     {
         return(false);
     }
     if (!IsOn.Equals(obj.IsOn))
     {
         return(false);
     }
     if (!Brightness.Equals(obj.Brightness))
     {
         return(false);
     }
     if (!Color.Equals(obj.Color))
     {
         return(false);
     }
     return(true);
 }
コード例 #5
0
ファイル: HueConnector.cs プロジェクト: magico13/HomeAPI
        /// <inheritdoc/>
        public async Task <bool> AlertLightAsync(long id)
        {
            if (credentials == null)
            {
                throw new UnauthorizedAccessException(UNCONFIGURED_EXCEPTION);
            }
            string url = $"{credentials.APIURL}lights/{id}/state";

            try
            {
                HueLight light = await GetLightAsync(id);

                light.State.Alert = HueLight.AlertType.lselect;

                string      stateObj = JsonConvert.SerializeObject(light.State).ToLower();
                HttpContent content  = new StringContent(stateObj);

                HttpResponseMessage response = await _client.PutAsync(url, content);

                string final = await response.Content.ReadAsStringAsync();

                return(final.Contains("success"));
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #6
0
ファイル: HueConnector.cs プロジェクト: magico13/HomeAPI
        /// <inheritdoc/>
        public async Task <HueLight> GetLightAsync(long id)
        {
            if (credentials == null)
            {
                throw new UnauthorizedAccessException(UNCONFIGURED_EXCEPTION);
            }
            string url = $"{credentials.APIURL}lights/{id}";

            try
            {
                HttpResponseMessage response = await _client.GetAsync(url);

                if (response.IsSuccessStatusCode)
                {
                    string content = await response.Content.ReadAsStringAsync();

                    HueLight light = JsonConvert.DeserializeObject <HueLight>(content);
                    light.ID = id;
                    return(light);
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(null);
        }
コード例 #7
0
        public void UpdateColor()
        {
            RGBColor rgb = HueLight.ToRGBColor();

            SolidColor = new SKColor(ClampToByte(rgb.R * 255), ClampToByte(rgb.G * 255), ClampToByte(rgb.B * 255));
            Color      = SolidColor.WithAlpha(Brightness);
        }
コード例 #8
0
        public void ToLight(string lightTypeName, LightType expectedLightType)
        {
            var hueLight = new HueLight()
            {
                Name  = "Light No. 5",
                Type  = lightTypeName,
                State = new HueLightState()
                {
                    On        = true,
                    Bri       = 100,
                    Ct        = 10,
                    Sat       = 50,
                    Hue       = 80,
                    Reachable = true
                }
            };

            var result = hueLight.ToLight(5);

            Assert.Equal(5, result.Id);
            Assert.Equal("Light No. 5", result.Name);
            Assert.Equal(expectedLightType, result.Type);
            Assert.True(result.State.On);
            Assert.Equal(100, result.State.Brightness);
            Assert.Equal(10, result.State.ColorTemperature);
            Assert.Equal(50, result.State.Saturation);
            Assert.Equal(80, result.State.Hue);
            Assert.True(result.State.Reachable);
        }
コード例 #9
0
        public void Initialize(HueLight light)
        {
            this.light    = light;
            nameText.text = light.name + "\n" + light.type + "\n" + light.modelID;

            onToggle.SetValue(light.state.on);
            hueSlider.SetValue(light.state.hue);
            brightnessSlider.SetValue(light.state.brightness);
            saturationSlider.SetValue(light.state.saturation);
            transitionTime.SetValue(light.state.transitionTime);

            colorLoopToggle.SetValue(light.state.effect != "none");

            hueSlider.gameObject.SetActive(light.isColor);
            saturationSlider.gameObject.SetActive(light.isColor);
            brightnessSlider.gameObject.SetActive(light.isDimmable);

            if (!light.isColor)
            {
                foreach (GameObject button in colorEffectObjects)
                {
                    button.SetActive(false);
                }
            }

            setSwatchColor();

            StartCoroutine(toggleWithSound());
        }
コード例 #10
0
        public async Task <ActionResult <string> > SetBrightnessAsync(long id, bool on)
        {
            HueLight light = await _hueConnector.GetLightAsync(id);

            light.State.On    = on;
            light.State.Alert = HueLight.AlertType.none;
            return(await _hueConnector.UpdateLightAsync(id, light.State));
        }
コード例 #11
0
        public int AddLight(HueLight light)
        {
            var nextId = Lights.Count + 1;

            light.Id = nextId;
            Lights.Add(nextId, light);
            return(nextId);
        }
コード例 #12
0
        public async Task <ActionResult <string> > ToggleLightAsync(long id)
        {
            HueLight light = await _hueConnector.GetLightAsync(id);

            light.State.On    = !light.State.On;
            light.State.Alert = HueLight.AlertType.none;

            return(await _hueConnector.UpdateLightAsync(id, light.State));
        }
コード例 #13
0
ファイル: HueLight.cs プロジェクト: sec9030/Hue
 public static HueLight Parse(dynamic d)
 {
     var instance = new HueLight();
     instance.state = HueLightState.Parse(d["state"]);
     instance.type = d["type"];
     instance.name = d["name"];
     instance.modelid = d["modelid"];
     instance.swversion = long.Parse(d["swversion"]);
     return instance;
 }
コード例 #14
0
        public static HueLight Parse(dynamic d)
        {
            var instance = new HueLight();

            instance.state     = HueLightState.Parse(d["state"]);
            instance.type      = d["type"];
            instance.name      = d["name"];
            instance.modelid   = d["modelid"];
            instance.swversion = long.Parse(d["swversion"]);
            return(instance);
        }
コード例 #15
0
        private void ParseLights(string json)
        {
            //{"lights":{"1":{"state": {"on":true,"bri":219,"hue":33863,"sat":49,"xy":[0.3680,0.3686],"ct":231,"alert":"none","effect":"none","colormode":"ct","reachable":true}, "type": "Extended color light", "name": "Hue Lamp 1", "modelid": "LCT001", "swversion": "65003148", "pointsymbol": { "1":"none", "2":"none", "3":"none", "4":"none", "5":"none", "6":"none", "7":"none", "8":"none" }},"2":{"state": {"on":true,"bri":219,"hue":33863,"sat":49,"xy":[0.3680,0.3686],"ct":231,"alert":"none","effect":"none","colormode":"ct","reachable":true}, "type": "Extended color light", "name": "Hue Lamp 2", "modelid": "LCT001", "swversion": "65003148", "pointsymbol": { "1":"none", "2":"none", "3":"none", "4":"none", "5":"none", "6":"none", "7":"none", "8":"none" }},"3":{"state": {"on":true,"bri":219,"hue":33863,"sat":49,"xy":[0.3680,0.3686],"ct":231,"alert":"none","effect":"none","colormode":"ct","reachable":true}, "type": "Extended color light", "name": "Hue Lamp 3", "modelid": "LCT001", "swversion": "65003148", "pointsymbol": { "1":"none", "2":"none", "3":"none", "4":"none", "5":"none", "6":"none", "7":"none", "8":"none" }}},"groups":{},"config":{"name": "Philips hue","mac": "00:17:88:09:62:40","dhcp": true,"ipaddress": "192.168.0.113","netmask": "255.255.255.0","gateway": "192.168.0.1","proxyaddress": "","proxyport": 0,"UTC": "2012-11-15T03:08:08","whitelist":{"c20aca42279b2898bb1ce2a470da6d64":{"last use date": "2012-11-14T23:41:41","create date": "2012-11-07T03:00:06","name": "Dmitri Sadakov’s iPhone"},"3b268b59109f63d7319c8f9d2a9d2edb":{"last use date": "2012-11-07T04:31:07","create date": "2012-11-07T04:28:27","name": "soapui"},"2cb1ac173bc8aa7f2cae5a073a11fa8f":{"last use date": "2012-11-12T02:40:02","create date": "2012-11-07T04:28:44","name": "soapui"},"26edc9a619306aa4b473ff22165751f":{"last use date": "2012-11-07T03:00:06","create date": "2012-11-07T04:28:45","name": "soapui"},"343855a103b881726d398c68ac6333":{"last use date": "2012-11-07T21:56:21","create date": "2012-11-07T19:22:04","name": "python_hue"},"b7a7e52143446771752ae6e1c69b0a3":{"last use date": "2012-11-07T21:56:21","create date": "2012-11-13T04:31:39","name": "WinHueApp"},"1ec60546129895441850019217b1753f":{"last use date": "2012-11-07T21:56:21","create date": "2012-11-15T01:35:34","name": "winhueapp"},"3fa667052b1747071bc90d137472433":{"last use date": "2012-11-07T21:56:21","create date": "2012-11-15T02:20:50","name": "winhueapp"},"28fd5ecc3add810fa0aaaa41e1db8a7":{"last use date": "2012-11-07T21:56:21","create date": "2012-11-15T02:23:55","name": "winhueapp"},"2c68b67e2d21c1c73e826292701a5eb":{"last use date": "2012-11-07T21:56:21","create date": "2012-11-15T02:25:20","name": "winhueapp"},"15706f6e1d8b9167d32b2822fe99f8b":{"last use date": "2012-11-15T02:31:25","create date": "2012-11-15T02:30:31","name": "winhueapp"},"1db73d762d1d8ea73c14bbda7fac1bb":{"last use date": "2012-11-07T21:56:21","create date": "2012-11-15T03:00:44","name": "winhueapp"},"f86f8213eacc771e26889e19d01083":{"last use date": "2012-11-15T03:08:08","create date": "2012-11-15T03:07:53","name": "winhueapp"}},"swversion": "01003542","swupdate":{"updatestate":0,"url":"","text":"","notify": false},"linkbutton": true,"portalservices": true},"schedules":{}}

            var jss    = new JavaScriptSerializer();
            var d      = jss.Deserialize <dynamic>(json);
            var lights = d["lights"];

            Lights = new ConcurrentDictionary <string, HueLight>();
            foreach (var light in lights)
            {
                Lights.TryAdd(light.Key, HueLight.Parse(light.Value));
            }
        }
コード例 #16
0
ファイル: Worker.cs プロジェクト: Kriez/dashboard
        public async Task ScanLightsAsync()
        {
            foreach (var item in (await _client.GetLightsAsync()))
            {
                HueLight hueLight = new HueLight()
                {
                    Id          = item.Id,
                    IsOn        = item.State.On,
                    IsReachable = item.State.IsReachable,
                    Name        = item.Name,
                    Brightness  = item.State.Brightness,
                    Color       = item.State.ToHex()
                };

                Lights.Add(hueLight);
            }
        }
コード例 #17
0
        public void MYSATHANDLER(object __sender__ /*HueLights.HueLight SENDER */, EventArgs ARGS)
        {
            HueLight SENDER = (HueLight )__sender__;

            try
            {
                SplusExecutionContext __context__ = SplusSimplSharpDelegateThreadStartCode();

                __context__.SourceCodeLine = 106;
                if (Functions.TestForTrue((Functions.BoolToInt(SENDER == MYLIGHT))))
                {
                    __context__.SourceCodeLine = 108;
                    SATOUT.Value = (ushort)(MYLIGHT.BulbSat);
                }
            }
            finally { ObjectFinallyHandler(); }
        }
コード例 #18
0
        public async Task <ActionResult <string> > SetBrightnessAsync(long id, double brightness)
        {
            int finalBrightness = 254;

            if (brightness <= 1 && brightness > 0)
            {
                //given as a float between 0 and 1
                finalBrightness = (int)Math.Max(1, Math.Min(254, brightness * 254));
            }
            else
            {
                //otherwise it's a number between 1 and 254
                finalBrightness = (int)Math.Round(Math.Max(1, Math.Min(254, brightness)));
            }
            HueLight light = await _hueConnector.GetLightAsync(id);

            light.State.Bri   = finalBrightness;
            light.State.On    = true; //if we're setting the brightness then we need to be on
            light.State.Alert = HueLight.AlertType.none;
            return(await _hueConnector.UpdateLightAsync(id, light.State));
        }
コード例 #19
0
        public static List <HueLight> GetLights(string bridgeIp, string userName)
        {
            WebClient client = new WebClient()
            {
                Encoding = Encoding.UTF8
            };
            string resp = client.DownloadString(string.Format("http://{0}/api/{1}/lights", bridgeIp, userName));

            JObject         dynobj = JObject.Parse(resp);
            List <HueLight> mylist = new List <HueLight>();

            for (int i = 1; i <= dynobj.Count; i++)
            {
                if (dynobj.ContainsKey(i.ToString()))
                {
                    JToken   mylight  = dynobj[i.ToString()];
                    HueLight hueLight = new HueLight();
                    hueLight.Id          = i.ToString();
                    hueLight.Name        = mylight["name"].ToString();
                    hueLight.Type        = mylight["type"].ToString();
                    hueLight.ProductName = mylight["productname"].ToString();
                    hueLight.SwitchedOn  = mylight["state"]["on"].ToString().Equals("True");

                    if (mylight["state"]["bri"] != null)
                    {
                        hueLight.Brightness = Convert.ToInt32(mylight["state"]["bri"].ToString());
                    }
                    else
                    {
                        hueLight.Brightness = -1;
                    }

                    mylist.Add(hueLight);
                }
            }

            return(mylist);
        }
コード例 #20
0
        public void MYONLINEHANDLER(object __sender__ /*HueLights.HueLight SENDER */, EventArgs ARGS)
        {
            HueLight SENDER = (HueLight )__sender__;

            try
            {
                SplusExecutionContext __context__ = SplusSimplSharpDelegateThreadStartCode();

                __context__.SourceCodeLine = 128;
                if (Functions.TestForTrue((Functions.BoolToInt(SENDER == MYLIGHT))))
                {
                    __context__.SourceCodeLine = 130;
                    LOADONLINE.Value           = (ushort)(MYLIGHT.BulbOnline);
                    __context__.SourceCodeLine = 131;
                    LIGHTTYPE.UpdateValue(MYLIGHT.BulbType);
                    __context__.SourceCodeLine = 132;
                    LOADREACHABLE.Value        = (ushort)(MYLIGHT.Reachable);
                    __context__.SourceCodeLine = 133;
                    MYLIGHT.GetBulb( );
                }
            }
            finally { ObjectFinallyHandler(); }
        }
コード例 #21
0
ファイル: PhilipsHueService.cs プロジェクト: jh12/OctoHome
 public async Task SwitchLightOff(HueLight light)
 {
     await _httpClient.PutAsync($"api/hue/light/{light.Id}/turn/off", null);
 }
コード例 #22
0
 public HueSwitchLightEventArgs(HueLight light, bool state, int brightness)
 {
     Light      = light;
     State      = state;
     Brightness = brightness;
 }
コード例 #23
0
 public Task SwitchLightOff(HueLight light)
 {
     return(Task.CompletedTask);
 }