Beispiel #1
0
 protected override async Task <string> RunAsync()
 {
     try
     {
         await _lifxClient.SetState(new All(), new SentState { Color = $"#{_newColor}", Duration = _duration, Power = "on" });
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         throw;
     }
     return(_newColor);
 }
Beispiel #2
0
        private async Task TestLifx()
        {
            // ***
            // *** Initialize the API
            // ***
            LifxApi api = new LifxApi("c1c1b8b4760452f88074f9457b728ce8b2c92f97cbabcd4dec6d7ccabd82011c");

            // ***
            // *** Validate a color
            // ***
            Color color = await api.ValidateColor("#ff0000");

            // ***
            // *** Lists the lights
            // ***
            IEnumerable <Light> lights = await api.ListLights(Selector.All);

            // ***
            // *** List the scenes
            // ***
            IEnumerable <Scene> sceneList = await api.ListScenes();

            // ***
            // *** Select a single light
            // ***
            Light light = lights.Where(t => t.Label == "iWindow").SingleOrDefault();

            // ***
            // ***
            // ***
            Mix mix = new Mix()
            {
                States = new SentState[]
                {
                    new SentState()
                    {
                        Brightness = 1, Color = "Red"
                    },
                    new SentState()
                    {
                        Brightness = 1, Color = "Green"
                    },
                    new SentState()
                    {
                        Brightness = 1, Color = "Blue"
                    },
                    new SentState()
                    {
                        Power = "off"
                    }
                },
                Defaults = new SentState()
                {
                    Power = "on", Duration = 1,
                }
            };

            await api.Cycle(light, mix);

            // ***
            // *** Create a list selector
            // ***
            ISelector items = Selector.CreateList(lights.ElementAt(0), lights.ElementAt(1));

            if (light != null)
            {
                await api.TogglePower(light, 3);

                await api.SetState(light, new SentState()
                {
                    Power = "on", Duration = 2, Color = "#1fa1b2"
                });
            }
        }