Example #1
0
        public HueLightingSystem(string name, string ip)
        {
            //var bridges = GetBridges();


            _client = new HueClient(ip);
            _client.RegisterAsync("ubilight", "ubilightkey");
            _client.Initialize("ubilightkey");
            Name = name;
        }
Example #2
0
        //private BridgeInfo _hueBridge;

        public ReleaseNight()
        {
            InitializeComponent();

            _navigationHelper            = new NavigationHelper(this);
            _navigationHelper.LoadState += NavigationHelperOnLoadState;
            _navigationHelper.SaveState += (sender, args) => { MediaSimple.MediaPlayer.Pause(); };

            //Task.Run(() => this.GetHueInfo()).Wait();
            //_hueClient = new LocalHueClient(_hueBridge.internalipaddress);
            //_hueClient.Initialize("");
            _hueClient = new LocalHueClient("10.10.10.193");
            _hueClient.Initialize("CqnjoQvPHKdy1IkFVJggaTdflgWBF1HWQTOZYf2p");
        }
Example #3
0
        public HueBuildLight(string ip, IEnumerable <string> lights, string intensity)
        {
            _hueClient = new HueClient(ip);
            _hueClient.Initialize(AppKey);
            _lights = lights.ToList();

            int parsedInt;

            if (int.TryParse(intensity, out parsedInt))
            {
                _intensity = parsedInt;
            }
            else
            {
                _intensity = MAX_INTENSITY;
            }
        }
Example #4
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);
        }
Example #5
0
        //private BridgeInfo _hueBridge;

        public RedAlert()
        {
            InitializeComponent();

            _navigationHelper            = new NavigationHelper(this);
            _navigationHelper.LoadState += NavigationHelperOnLoadState;
            _navigationHelper.SaveState += (sender, args) => { MediaSimple.MediaPlayer.Pause(); };

            //Task.Run(() => this.GetHueInfo()).Wait();
            //_hueClient = new LocalHueClient(_hueBridge.internalipaddress);
            //_hueClient.Initialize("");

            //TODO: Complete Hue bridge self discovery
            //Until then I utilized the instructions at  https://developers.meethue.com/documentation/getting-started
            // to hard code my info gathered from my router.
            _hueClient = new LocalHueClient("10.10.10.193");
            _hueClient.Initialize("CqnjoQvPHKdy1IkFVJggaTdflgWBF1HWQTOZYf2p");
        }
Example #6
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);
        }
        /// <summary>
        /// Called when the package is started.
        /// </summary>
        public override void OnStart()
        {
            PackageHost.WriteInfo("Connecting to " + PackageHost.GetSettingValue <string>("BridgeAddress"));
            hueClient = new HueClient(PackageHost.GetSettingValue <string>("BridgeAddress"));
            hueClient.Initialize(PackageHost.GetSettingValue <string>("BridgeUsername"));

            PackageHost.WriteInfo("Getting configuration");
            var bridge = hueClient.GetBridgeAsync().GetAwaiter().GetResult();

            PackageHost.PushStateObject <BridgeConfig>("BridgeConfig", bridge.Config);
            foreach (Light light in bridge.Lights)
            {
                PackageHost.PushStateObject <Light>(light.Name, light);
            }

            PackageHost.WriteInfo("Starting query process");
            Task.Factory.StartNew(() =>
            {
                int pause = 1000;
                while (PackageHost.IsRunning)
                {
                    try
                    {
                        var lights = hueClient.GetLightsAsync().GetAwaiter().GetResult();
                        foreach (Light light in lights)
                        {
                            PackageHost.PushStateObject <Light>(light.Name, light);
                        }
                        pause = 1000;
                    }
                    catch (Exception ex)
                    {
                        if (pause < 60000)
                        {
                            pause *= 2;
                        }
                        PackageHost.WriteError("Error to query lights : {0}", ex.ToString());
                    }
                    Thread.Sleep(pause);
                }
            });

            PackageHost.WriteInfo("Connected to {0}", hueClient.ApiBase);
        }
Example #8
0
        //private BridgeInfo _hueBridge;

        public Imperial()
        {
            InitializeComponent();

            _navigationHelper            = new NavigationHelper(this);
            _navigationHelper.LoadState += NavigationHelperOnLoadState;
            //_navigationHelper.SaveState += (sender, args) => { MediaSimple.MediaPlayer.Pause(); };

            //Task.Run(() => this.GetHueInfo()).Wait();
            //_hueClient = new LocalHueClient(_hueBridge.internalipaddress);
            //_hueClient.Initialize("");

            BitmapImage bitmapImage = new BitmapImage();

            // Call BaseUri on the root Page element and combine it with a relative path
            // to consruct an absolute URI.
            bitmapImage.UriSource = new Uri(BaseUri, "/Assets/vadar2.jpg");
            IMImage.Source        = bitmapImage;


            _hueClient = new LocalHueClient("10.10.10.193");
            _hueClient.Initialize("CqnjoQvPHKdy1IkFVJggaTdflgWBF1HWQTOZYf2p");
        }
Example #9
0
 internal void Initialize(string p)
 {
     _hueClient.Initialize(p);
 }