Exemplo n.º 1
0
        public void CalculateLightCommands_AllLightStyles_EverythingChanges()
        {
            using (ShimsContext.Create())
            {
                Hue hue = new Hue(null);

                hue.UpdateFluxStatus(BrightnessMatches, CurrentColorTemperature);

                Dictionary <LightCommand, IList <string> > result = hue.CalculateLightCommands(
                    DefaultLightTestGroup,
                    CurrentColorTemperature - 5,
                    25);

                LightCommand lightCommandKey1 = result.Keys.SingleOrDefault(x => x.Brightness == 25 && x.ColorTemperature == null);
                LightCommand lightCommandKey2 = result.Keys.SingleOrDefault(x => x.Brightness == null && x.ColorTemperature == CurrentColorTemperature - 5);
                LightCommand lightCommandKey3 = result.Keys.SingleOrDefault(x => x.Brightness == 25 && x.ColorTemperature == CurrentColorTemperature - 5);

                Assert.IsNotNull(lightCommandKey1);
                Assert.IsNotNull(lightCommandKey2);
                Assert.IsNotNull(lightCommandKey3);

                Assert.AreEqual(3, result.Count(), $"Three light groups to update. ColorTemp only, Brightness and ColorTemp, and Brightness only.");
                Assert.AreEqual(2, result[lightCommandKey1].Count, $"Brightness Only.");
                Assert.AreEqual(3, result[lightCommandKey2].Count, $"ColorTemp Only.");
                Assert.AreEqual(3, result[lightCommandKey3].Count, $"Brightness and ColorTemp.");
            }
        }
Exemplo n.º 2
0
        public void CalculateLightCommands_AllLightStyles_NoChange()
        {
            using (ShimsContext.Create())
            {
                Hue hue = new Hue(null);

                hue.UpdateFluxStatus(BrightnessMatches, CurrentColorTemperature);

                Dictionary <LightCommand, IList <string> > result = hue.CalculateLightCommands(
                    DefaultLightTestGroup,
                    CurrentColorTemperature,
                    BrightnessMatches);

                Assert.AreEqual(0, result.Count(), $"No change is expected.");
            }
        }
Exemplo n.º 3
0
        public void CalculateLightCommands_AllLightStyles_ColorTemperatureChange_OutsideWhiteAmbienceRange()
        {
            using (ShimsContext.Create())
            {
                Hue hue = new Hue(null);

                hue.UpdateFluxStatus(BrightnessMatches, CurrentColorTemperature);

                Dictionary <LightCommand, IList <string> > result = hue.CalculateLightCommands(
                    DefaultLightTestGroup,
                    ColorTemperatureExtensions.MaxAllowedColorTemperatureForWhiteAmbianceLights + 5,
                    BrightnessMatches);

                LightCommand lightCommandKey = result.Keys.SingleOrDefault(x => x.ColorTemperature == ColorTemperatureExtensions.MaxAllowedColorTemperatureForWhiteAmbianceLights + 5);
                Assert.IsNotNull(lightCommandKey);

                Assert.AreEqual(1, result.Count(), $"Brightness change not expected so all lights should be updated for color temperature change.");
                Assert.AreEqual(4, result[lightCommandKey].Count, $"Color lights to be updated. White Ambiance lights to be excluded.");
            }
        }
Exemplo n.º 4
0
        public void CalculateLightCommands_AllLightStyles_BrightnessChange()
        {
            using (ShimsContext.Create())
            {
                Hue hue = new Hue(null);

                hue.UpdateFluxStatus(BrightnessMatches, CurrentColorTemperature);

                Dictionary <LightCommand, IList <string> > result = hue.CalculateLightCommands(
                    DefaultLightTestGroup,
                    CurrentColorTemperature,
                    BrightnessDim);

                LightCommand lightCommandKey = result.Keys.SingleOrDefault(x => x.Brightness == BrightnessDim);
                Assert.IsNotNull(lightCommandKey);

                Assert.AreEqual(1, result.Count(), $"One sets of light groups should be updated for brightness change.");
                Assert.AreEqual(5, result[lightCommandKey].Count, $"Only brightness matches lights should be updated.");
            }
        }
Exemplo n.º 5
0
        public void CalculateLightCommands_BrightnessGroupMatch_GroupHasMismatch()
        {
            using (ShimsContext.Create())
            {
                Hue hue = new Hue(null);

                hue.UpdateFluxStatus(145, CurrentColorTemperature);

                Dictionary <LightCommand, IList <string> > result = hue.CalculateLightCommands(
                    new List <Light>()
                {
                    new Light()
                    {
                        Name  = "Test 1",
                        Type  = LightExtensions.LightTypeToNameMapping[LightType.WhiteAmbiance],
                        State = new State()
                        {
                            On = true, Brightness = 145, ColorTemperature = CurrentColorTemperature
                        }
                    },

                    new Light()
                    {
                        Name  = "Test 2",
                        Type  = LightExtensions.LightTypeToNameMapping[LightType.WhiteAmbiance],
                        State = new State()
                        {
                            On = true, Brightness = 147, ColorTemperature = CurrentColorTemperature
                        }
                    },
                },
                    CurrentColorTemperature,
                    146);

                LightCommand lightCommandKey = result.Keys.SingleOrDefault(x => x.Brightness == 146 && x.ColorTemperature == null);
                Assert.IsNotNull(lightCommandKey, "Brightness for a group is rounded to the highest common value.");

                Assert.AreEqual(1, result.Count(), $"One light group expected since all lights share the same common name.");
                Assert.AreEqual(2, result[lightCommandKey].Count, $"Both lights should be adjusted.");
            }
        }
Exemplo n.º 6
0
        public void CalculateLightCommands_Brightness_Single(byte currentBrightness)
        {
            Primitives.Brightness newBrightness = 128;

            using (ShimsContext.Create())
            {
                Hue hue = new Hue(null);

                hue.UpdateFluxStatus(currentBrightness, CurrentColorTemperature);

                Dictionary <LightCommand, IList <string> > result = hue.CalculateLightCommands(
                    new List <Light>()
                {
                    new Light()
                    {
                        Name  = "Test",
                        Type  = LightExtensions.LightTypeToNameMapping[LightType.WhiteAmbiance],
                        State = new State()
                        {
                            On = true, Brightness = currentBrightness, ColorTemperature = CurrentColorTemperature
                        }
                    },
                },
                    CurrentColorTemperature,
                    newBrightness);

                bool brightnessChangeExpected = currentBrightness == 0 || currentBrightness != newBrightness;

                Assert.AreEqual(brightnessChangeExpected ? 1 : 0, result.Count(), $"One light group expected since change is expected.");

                if (brightnessChangeExpected)
                {
                    Assert.AreEqual((byte?)newBrightness, result.First().Key.Brightness, $"Brightness level should be new level.");
                    Assert.AreEqual(1, result.First().Value.Count, $"1 light in group expected.");
                }
            }
        }