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; }
private static void RegisterHueClient(ContainerBuilder builder) { var appBridgeIP = ConfigurationManager.AppSettings["bridgeIP"]; var appKey = ConfigurationManager.AppSettings["appKey"]; var client = new LocalHueClient(appBridgeIP); client.Initialize(appKey); builder.RegisterInstance(client).ExternallyOwned(); }
/// <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); }
private async void OnBridgeFound(object sender, PhilipsHueBridge bridge) { var variableName = $"PhilipsHue.{bridge.Id}.ApiKey"; var apiKey = _variableRepository.Get<StringVariable>(variableName).Value; var client = new LocalHueClient(bridge.IpAddress, apiKey); var bulbs = await client.GetLightsAsync(); var sensors = await client.GetSensorsAsync(); if (bulbs != null) { foreach (var light in bulbs) { var id = light.UniqueId.Replace(":", string.Empty).Replace("-", string.Empty); var bulb = new PhilipsHueBulb(light.Id, id, light.Name, bridge) { Icon = "PhilipsHueIcon PhilipsHueIcon_" + light.ModelId, Model = light.ModelId }; OnBulbFound(bulb); } } if (sensors != null) { var presenceSensors = sensors .Where(s => s.ModelId == "SML001" && s.Type == "ZLLPresence") .ToList(); foreach (var presenceSensor in presenceSensors) { var id = presenceSensor.UniqueId.Replace(":", string.Empty).Replace("-", string.Empty); var sensor = new PhilipsHuePresenceSensor(presenceSensor.Id, id, presenceSensor.Name, bridge) { Model = presenceSensor.ModelId, Icon = "PhilipsHueIcon PhilipsHueIcon_PresenceSensor", Battery = presenceSensor.Config.Battery ?? 100 }; OnPresenceSensorFound(sensor); } } }
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); } }
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); }
void CreateClient() { if (!string.IsNullOrEmpty(Helpers.Settings.AppKey)) { client = new LocalHueClient(Helpers.Settings.DefaultBridgeIP, Helpers.Settings.AppKey); client.Initialize(Helpers.Settings.AppKey); } else Acr.UserDialogs.UserDialogs.Instance.ShowError("No Hue Client found"); }
public async Task<string> Initialize(string bridgeIP) { ILocalHueClient client = new LocalHueClient(bridgeIP); return await client.RegisterAsync("ConsoleApp", "Desktop"); }
public LightCommandExecutor(LocalHueClient hueClient) { this._hueClient = hueClient; }