Пример #1
0
        public async Task SetNameTest()
        {
            var bridge = await BridgeTests.GetLoggedInBridge();

            var lights = (HueObjectCollectionBase <Light>) await bridge.GetLightsAsync();

            Light light = lights.FirstOrDefault();

            if (light != null)
            {
                light = await light.GetAttributesAsync() as Light;

                Assert.IsNotNull(light);
                string oldName = light.Name;
                Assert.IsInstanceOfType(await light.SetNameAsync <Light>("New Light Name Test"), typeof(HueObjectCollectionBase <Success>));
                light = await light.GetAttributesAsync() as Light;

                Assert.IsNotNull(light);
                Assert.AreEqual(light.Name, "New Light Name Test");
                Assert.IsInstanceOfType(await light.SetNameAsync <Light>(oldName), typeof(HueObjectCollectionBase <Success>));
                light = await light.GetAttributesAsync() as Light;

                Assert.IsNotNull(light);
                Assert.AreEqual(light.Name, oldName);
            }
        }
Пример #2
0
        public async Task SetAttributesTest()
        {
            var bridge = await BridgeTests.GetLoggedInBridge();

            var command = new Command {
                Address = "/api/0/groups/1/action", Method = "PUT"
            };

            command.Body.Add("on", true);
            command.Body.Add("Hue", 25400);
            command.Body.Add("Brightness", 254);
            command.Body.Add("Saturation", 254);

            var schedule = new Schedule(command, DateTime.Now.AddMinutes(1))
            {
                Description = "test schedule " + GetRandomString(), Name = "test schedule"
            };

            var rv = await bridge.CreateScheduleAsync(schedule) as HueObjectCollectionBase <Success>;

            Assert.IsNotNull(rv);

            string id = (from kvp in rv.Dictionary select kvp.Value.PathValue).FirstOrDefault();

            Assert.IsNotNull(id);

            var schedules = await bridge.GetSchedulesAsync() as HueObjectCollectionBase <Schedule>;

            Assert.IsNotNull(schedules);

            var createdSchedule = schedules.Dictionary[id];

            Assert.IsNotNull(createdSchedule);

            createdSchedule = await createdSchedule.GetAttributesAsync() as Schedule;

            Assert.IsNotNull(createdSchedule);

            Assert.AreEqual(schedule.Description, createdSchedule.Description);

            schedule = new Schedule {
                Description = "new description"
            };

            Assert.IsInstanceOfType(await createdSchedule.SetAttributesAsync(schedule), typeof(HueObjectCollectionBase <Success>));

            var alteredSchedule = await createdSchedule.GetAttributesAsync() as Schedule;

            Assert.IsNotNull(alteredSchedule);

            Assert.AreEqual(schedule.Description, alteredSchedule.Description);

            Assert.IsInstanceOfType(await bridge.DeleteScheduleAsync(id), typeof(HueObjectCollectionBase <Success>));
        }
Пример #3
0
        public async Task GetGroupAttributesTest()
        {
            var bridge = await BridgeTests.GetLoggedInBridge();

            var groups = (HueObjectCollectionBase <Group>) await bridge.GetGroupsAsync();

            Group group = groups.Dictionary.Values.FirstOrDefault();

            if (group != null)
            {
                //Assert.IsNull(group.State);
                group = await group.GetAttributesAsync() as Group;

                Assert.IsNotNull(group);
                Assert.IsNotNull(group.State);
            }
        }
Пример #4
0
        public async Task GetAttributesTest()
        {
            var bridge = await BridgeTests.GetLoggedInBridge();

            var lights = (HueObjectCollectionBase <Light>) await bridge.GetLightsAsync();

            Light light = lights.Dictionary.Values.FirstOrDefault();

            if (light != null)
            {
                //Assert.IsNull(light.State);
                light = await light.GetAttributesAsync() as Light;

                Assert.IsNotNull(light);
                Assert.IsNotNull(light.State);
            }
        }
Пример #5
0
        public async Task SetStateTest()
        {
            var bridge = await BridgeTests.GetLoggedInBridge();

            var groups = (HueObjectCollectionBase <Group>) await bridge.GetGroupsAsync();

            var oldStates = new Dictionary <string, State>();

            foreach (Group rv in groups.Dictionary.Values)
            {
                var group = await rv.GetAttributesAsync() as Group;

                Assert.IsNotNull(group);
                oldStates.Add(rv.ID, group.State);
                var newState = new State {
                    Hue = 46920, Brightness = 254, Saturation = 254, On = true
                };
                Assert.IsInstanceOfType(await rv.SetStateAsync(newState), typeof(HueObjectCollectionBase <Success>));
                System.Threading.Thread.Sleep(3000);
                group = await rv.GetAttributesAsync() as Group;

                Assert.IsNotNull(group);
                Assert.AreEqual(group.State.Hue, newState.Hue);
                Assert.AreEqual(group.State.Brightness, newState.Brightness);
                Assert.AreEqual(group.State.Saturation, newState.Saturation);
                Assert.AreEqual(group.State.ColorMode, "hs");
            }

            foreach (KeyValuePair <string, State> rv in oldStates)
            {
                var group = groups.Dictionary[rv.Key];
                Assert.IsNotNull(group);
                State newState;

                switch (rv.Value.ColorMode)
                {
                case "hs":
                    newState = new State
                    {
                        Hue        = rv.Value.Hue,
                        Brightness = rv.Value.Brightness,
                        Saturation = rv.Value.Saturation,
                        On         = rv.Value.On
                    };
                    Assert.IsInstanceOfType(await group.SetStateAsync(newState),
                                            typeof(HueObjectCollectionBase <Success>));
                    group = await group.GetAttributesAsync() as Group;

                    Assert.IsNotNull(group);
                    Assert.AreEqual(group.State.Hue, newState.Hue);
                    Assert.AreEqual(group.State.Brightness, newState.Brightness);
                    Assert.AreEqual(group.State.Saturation, newState.Saturation);
                    //Assert.AreEqual(group.State.ColorMode, "hs");
                    break;

                case "xy":
                    newState = new State {
                        CIEColor = rv.Value.CIEColor, On = rv.Value.On
                    };
                    Assert.IsInstanceOfType(await group.SetStateAsync(newState),
                                            typeof(HueObjectCollectionBase <Success>));
                    group = await group.GetAttributesAsync() as Group;

                    Assert.IsNotNull(group);
                    Assert.AreEqual(group.State.CIEColor[0], newState.CIEColor[0]);
                    Assert.AreEqual(group.State.CIEColor[1], newState.CIEColor[1]);
                    //Assert.AreEqual(group.State.ColorMode, "xy");
                    break;

                case "ct":
                    newState = new State {
                        ColorTemperature = rv.Value.ColorTemperature, On = rv.Value.On
                    };
                    Assert.IsInstanceOfType(await group.SetStateAsync(newState),
                                            typeof(HueObjectCollectionBase <Success>));
                    group = await group.GetAttributesAsync() as Group;

                    Assert.IsNotNull(group);
                    Assert.AreEqual(group.State.ColorTemperature, newState.ColorTemperature);
                    //Assert.AreEqual(group.State.ColorMode, "ct");
                    break;
                }
            }
        }
Пример #6
0
        public async Task SetStateTest()
        {
            var bridge = await BridgeTests.GetLoggedInBridge();

            var connection = bridge.Connect();

            connection.Throttle = true;

            var lights = (HueObjectCollectionBase <Light>) await bridge.GetLightsAsync();

            var oldStates = new Dictionary <string, State>();

            Debug.WriteLine(string.Join(Environment.NewLine, lights.Select(l => l.Type)));

            foreach (Light rv in lights.Dictionary.Values)
            {
                var light = await rv.GetAttributesAsync() as Light;

                Assert.IsNotNull(light);
                oldStates.Add(rv.ID, light.State);

                State newState;

                if (light.SupportedColorModes.Contains(Enumerations.ColorMode.HueSaturation))
                {
                    newState = new State {
                        Hue = 0, Brightness = 254, Saturation = 254, On = true
                    };
                }
                else
                {
                    newState = new State {
                        Brightness = 254, On = true
                    };
                }

                Assert.IsInstanceOfType(await rv.SetStateAsync(newState),
                                        typeof(HueObjectCollectionBase <Success>));
                System.Threading.Thread.Sleep(150);
                light = await rv.GetAttributesAsync() as Light;

                Assert.IsNotNull(light);
                Assert.AreEqual(light.State.Hue, newState.Hue);
                Assert.AreEqual(light.State.Brightness, newState.Brightness);
                Assert.AreEqual(light.State.Saturation, newState.Saturation);

                if (light.SupportedColorModes.Contains(Enumerations.ColorMode.HueSaturation))
                {
                    Assert.AreEqual(light.State.ColorMode, "hs");
                }
                else
                {
                    Assert.AreEqual(light.State.ColorMode, null);
                }
                System.Threading.Thread.Sleep(100);
            }

            System.Threading.Thread.Sleep(3000);

            foreach (KeyValuePair <string, State> rv in oldStates)
            {
                var light = lights.Dictionary[rv.Key];
                Assert.IsNotNull(light);
                State newState;

                switch (rv.Value.ColorMode)
                {
                case "hs":
                    newState = new State
                    {
                        Hue        = rv.Value.Hue,
                        Brightness = rv.Value.Brightness,
                        Saturation = rv.Value.Saturation,
                        On         = rv.Value.On
                    };
                    Assert.IsInstanceOfType(await light.SetStateAsync(newState),
                                            typeof(HueObjectCollectionBase <Success>));
                    System.Threading.Thread.Sleep(150);
                    light = await light.GetAttributesAsync() as Light;

                    Assert.IsNotNull(light);
                    Assert.AreEqual(light.State.Hue, newState.Hue);
                    Assert.AreEqual(light.State.Brightness, newState.Brightness);
                    Assert.AreEqual(light.State.Saturation, newState.Saturation);
                    Assert.AreEqual(light.State.ColorMode, "hs");
                    break;

                case "xy":
                    newState = new State {
                        CIEColor = rv.Value.CIEColor, On = rv.Value.On
                    };
                    Assert.IsInstanceOfType(await light.SetStateAsync(newState),
                                            typeof(HueObjectCollectionBase <Success>));
                    System.Threading.Thread.Sleep(150);
                    light = await light.GetAttributesAsync() as Light;

                    Assert.IsNotNull(light);
                    Assert.AreEqual(light.State.CIEColor[0], newState.CIEColor[0]);
                    Assert.AreEqual(light.State.CIEColor[1], newState.CIEColor[1]);
                    Assert.AreEqual(light.State.ColorMode, "xy");
                    break;

                case "ct":
                    newState = new State {
                        ColorTemperature = rv.Value.ColorTemperature, On = rv.Value.On
                    };
                    Assert.IsInstanceOfType(await light.SetStateAsync(newState),
                                            typeof(HueObjectCollectionBase <Success>));
                    System.Threading.Thread.Sleep(150);
                    light = await light.GetAttributesAsync() as Light;

                    Assert.IsNotNull(light);
                    Assert.AreEqual(light.State.ColorTemperature, newState.ColorTemperature);
                    Assert.AreEqual(light.State.ColorMode, "ct");
                    break;
                }
                System.Threading.Thread.Sleep(100);
            }
        }