Ejemplo n.º 1
0
        public async Task<ILight> GetLightAsync(string lightName)
        {
            string lightID = await this.GetLightIDAsync(lightName);
            ILight light = new Light();

            Dictionary<string, ILight> lights = new Dictionary<string, ILight>();

            using (var client = new HttpClient())
            {
                client.BaseAddress = new System.Uri("http://" + HueConfiguration.BridgeAddress);

                HttpResponseMessage response = await client.GetAsync("/api/" + HueConfiguration.UserName + "/lights/" + lightID);

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

                    light = JsonConvert.DeserializeObject<Light>(responseString);
                    light.ID = lightID;
                }
            }

            return light;
        }
Ejemplo n.º 2
0
        public async Task<Light> GetLightAsync(IHueDotNetConfigurationReader hueDotNetconfigurationReader, string lightName)
        {
            Light light = new Light();
            Dictionary<string, Light> lights = await this.GetLightsAsync(hueDotNetconfigurationReader);

            foreach (Light candidateLight in lights.Values)
            {
                if (candidateLight.Name.Equals(lightName, StringComparison.CurrentCultureIgnoreCase))
                {
                    light = candidateLight;
                    break;
                }
            }

            return light;
        }