Ejemplo n.º 1
0
        public HueLightingSystem(string name, string ip)
        {
            //var bridges = GetBridges();


            _client = new HueClient(ip);
            _client.RegisterAsync("ubilight", "ubilightkey");
            _client.Initialize("ubilightkey");
            Name = name;
        }
Ejemplo n.º 2
0
        public void SetBridge(string bridgeIP, string appKey, bool alreadyRegistered)
        {
            _hue = new HueClient(bridgeIP);

            if (alreadyRegistered)
            {
                _hue.Initialize(appKey);
            }
            else
            {
                var retryCount = 0;
                var regOk      = false;
                while (!regOk || retryCount >= RETRY_MAX)
                {
                    var reg = _hue.RegisterAsync(APP_NAME, appKey);
                    reg.Wait();
                    if (!reg.Result)
                    {
                        ShowWarning("Please press the button on the bridge to register the application", 30);
                    }
                    else
                    {
                        regOk = true;
                    }

                    retryCount++;
                    if (!regOk && retryCount < RETRY_MAX)
                    {
                        Thread.Sleep(RETRY_DELAY);
                    }
                }

                if (!regOk)
                {
                    ShowError("Failed to register application with bridge", 30);
                }
            }

            var lights = _hue.GetLightsAsync();

            lights.Wait();

            var choices = lights.Result.Select(x => new Tuple <string, string>(x.Id, string.Format("{0} ({1})", x.Name, x.Type))).ToList();

            UpdateLightChoice(choices);
        }
Ejemplo n.º 3
0
        public override int Run(string[] remainingArguments)
        {
            var hueClient = new HueClient(_ip);
            var result    = hueClient.RegisterAsync(HueBuildLight.AppName, HueBuildLight.AppKey).Result;

            if (result)
            {
                Console.WriteLine("Registered correctly.");
                return(0);
            }

            //If we failed to register, attempt to initialise and see if we succeed as we may already be registered.
            hueClient.Initialize(HueBuildLight.AppKey);
            var initialised = hueClient.IsInitialized;

            Console.WriteLine(initialised ? "Already registered." : "Failed to register");
            return(initialised ? 0 : 1);
        }
Ejemplo n.º 4
0
        internal async void Register(string p)
        {
            var result = await RegisterDataLoader.LoadAsync(() => _hueClient.RegisterAsync(p, p));

            RegisterSuccess = result;
        }