Exemplo n.º 1
0
 public static async Task Disconnect(StreamingHueClient client)
 {
     if (LightInfo.client != null)
     {
         client.Close();
         LightInfo.disconnect();
         origLeft  = new Color(1, 0, 0);
         origRight = new Color(0, 0, 1);
         Debug.Log("Disconnected");
     }
 }
Exemplo n.º 2
0
        public static async Task connect(CancellationToken token, string ip = null)
        {
            if (ip == null)
            {
                ip = await FindBridge();
            }
            token.ThrowIfCancellationRequested();
            var appKey    = Settings.ChromaConfig.Instance.HueAppKey;
            var clientKey = Settings.ChromaConfig.Instance.HueClientKey;

            Debug.Log("Connecting to bridge...");
            var client = new StreamingHueClient(ip, appKey, clientKey);

            token.ThrowIfCancellationRequested();
            Debug.Log("Connected! Getting entertainment group...");
            var group = (await client.LocalHueClient.GetEntertainmentGroups()).FirstOrDefault();

            if (group == null)
            {
                Debug.Log("Group is missing!");
                return;
            }
            token.ThrowIfCancellationRequested();
            var entGroup = new StreamingGroup(group.Locations);

            Debug.Log("Found group! Connecting to lightbulbs...");
            await client.Connect(group.Id);

            token.ThrowIfCancellationRequested();
            Debug.Log("Connected to bulbs! Syncing...");
            _ = client.AutoUpdate(entGroup, token);
            var entLayer = entGroup.GetNewLayer(true);

            LightInfo.setInfo(client, entLayer, token);
            await Task.Delay(TimeSpan.FromMilliseconds(50), token);

            if (Settings.ChromaConfig.Instance.LowLight == true)
            {
                entLayer.SetState(token, new RGBColor(255, 255, 255), 0.5);
            }
        }