RegisterAsync() public méthode

Register your applicationName and deviceName at the Hue Bridge.
or is null. or aren't long enough, are empty or contains spaces.
public RegisterAsync ( string applicationName, string deviceName ) : Task
applicationName string The name of your app.
deviceName string The name of the device.
Résultat Task
        private async Task<string> GetApiKeyWithBridgeButtonClick(PhilipsHueBridge bridge)
        {
            var endTime = DateTime.UtcNow.AddSeconds(30);
            var client = new LocalHueClient(bridge.IpAddress);

            while (DateTime.UtcNow < endTime)
            {
                try
                {
                    var machineName = Environment.MachineName.Replace(' ', '_');

                    if (machineName.Length > 19)
                    {
                        machineName = machineName.Substring(0, 19);
                    }

                    var appKey = await client.RegisterAsync("Xpressive.Home", machineName);
                    return appKey;
                }
                catch { }

                await Task.Delay(TimeSpan.FromSeconds(1));
            }

            return null;
        }
        /// <summary>
        /// Register your <paramref name="applicationName"/> and <paramref name="deviceName"/> at the Hue Bridge.
        /// </summary>
        /// <param name="applicationName">The name of your app.</param>
        /// <param name="deviceName">The name of the device.</param>
        /// <param name="generateClientKey">Set to true if you want a client key to use the streaming api</param>
        /// <returns>Secret key for the app to communicate with the bridge.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="applicationName"/> or <paramref name="deviceName"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException"><paramref name="applicationName"/> or <paramref name="deviceName"/> aren't long enough, are empty or contains spaces.</exception>

        public async Task <RegisterEntertainmentResult> RegisterAsync(string applicationName, string deviceName, bool generateClientKey)
        {
            var result = await LocalHueClient.RegisterAsync(_ip, applicationName, deviceName, generateClientKey);

            if (result != null)
            {
                Initialize(result.Username);

                if (!string.IsNullOrWhiteSpace(result.StreamingClientKey))
                {
                    InitializeStreaming(result.StreamingClientKey);
                }
            }

            return(result);
        }
Exemple #3
0
		protected override async void OnStart ()
		{

            try
            {
                var locator = new HttpBridgeLocator();
                var bridgeIPs = await locator.LocateBridgesAsync(TimeSpan.FromSeconds(5));

                // Handle when your app starts
                ILocalHueClient client = new LocalHueClient("ip");
                var appKey = await client.RegisterAsync("mypersonalappname", "mydevicename");
                client.Initialize("mypersonalappkey");
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.Message);
            }


        }
Exemple #4
0
        private static async Task <bool> localInit()
        {
            ipAddress = await SetUpIP();

            if (ipAddress == null)
            {
                return(true);
            }

            if (AppKey == null)
            {
                client = new Q42.HueApi.LocalHueClient(ipAddress);
                try
                {
                    await Task.Delay(PhilipsDelay);

                    var res = await client.RegisterAsync(APP_NAME, DEVICE_NAME);

                    if (res == null)
                    {
                        await Task.Delay(PhilipsDelay);

                        bool ret = await localInit();

                        return(ret);
                    }

                    AppKey = res;
                    client.Initialize(res);
                }
                catch (Exception err)
                {
                    if (err.Message == ERROR_MESSAGE)
                    {
                        if (messageDialog != null)
                        {
                            return(false);
                        }

                        if (!promptLinkButton)
                        {
                            promptLinkButton = true;
                            bool ret = Prompt.Invoke();
                            if (ret == true)
                            {
                                await Task.Delay(PhilipsDelay + PhilipsDelay);

                                ret = await localInit();
                            }
                            promptLinkButton = false;
                        }
                        return(true);
                    }
                }
            }
            else
            {
                client = new Q42.HueApi.LocalHueClient(ipAddress, AppKey);
            }

            if (await setUpLamps())
            {
                CompletedInit();
            }

            return(true);
        }
Exemple #5
0
		public async Task<string> Initialize(string bridgeIP)
		{
			ILocalHueClient client = new LocalHueClient(bridgeIP);
			return await client.RegisterAsync("ConsoleApp", "Desktop");
		}