Beispiel #1
0
        private static async Task TestLightCapabilities(ILight light)
        {
            // Perform basic tests:
            light.SwitchOn();
            Console.WriteLine($"\tAfter switching on, the light is {(light.IsOn() ? "on" : "off")}");
            light.SwitchOff();
            Console.WriteLine($"\tAfter switching off, the light is {(light.IsOn() ? "on" : "off")}");

            if (light is ITimerLight timer)
            {
                Console.WriteLine("\tTesting timer function");
                await timer.TurnOnFor(1000);

                Console.WriteLine("\tTimer function completed");
            }
            else
            {
                Console.WriteLine("\tTimer function not supported.");
            }

            if (light is IBlinkingLight blinker)
            {
                Console.WriteLine("\tTesting blinking function");
                await blinker.Blink(500, 5);

                Console.WriteLine("\tBlink function completed");
            }
            else
            {
                Console.WriteLine("\tBlink function not supported.");
            }
        }
Beispiel #2
0
        private void PressButtonLight(object sender)
        {
            //var names = HueProxy.DeviceNames;
            //string buttonName = names.Cast<object>().Aggregate("", (current, name) => current + (" " + name));
            //Value = buttonName;
            //RisePropertyChange(nameof(Value));

            ILight light = HueProxy.GetLightContainsName((sender as Button).Name);

            if (light.IsOn())
            {
                light.SwitchOff();
            }
            else
            {
                light.SwitchOn();
            }
        }