private static async Task <string> SetPower(LightBulb bulb, string eventid, string powerState) { var taskTimeOut = GetAppSetting("TaskTimeout", TaskTimeoutDefault); var taskTimeOutInc = GetAppSetting("TaskTimeoutInc", TaskTimeoutIncDefault); var commandSends = GetAppSetting("CommandSends", CommandSendsDef); // bulb.State = await _client.GetLightStateAsync(bulb); if (powerState == "toggle") { powerState = bulb.State.IsOn ? "off" : "on"; } for (var count = 0; count < commandSends; ++count) { var rr = taskTimeOut + (taskTimeOutInc * count); var to = GetTS(rr); Log.Bulb($"{eventid} SetPower {bulb.State.Label} {powerState} Try: {count}/{commandSends} TimeOut: {to}"); var res = await _client.SetDevicePowerStateAsync(bulb, powerState == "on").TimeoutAfter(to).ConfigureAwait(true); if (!res) { continue; } count = commandSends + 10; } Log.Bulb($"{eventid} SetPower {bulb.State.Label} {powerState} Done"); return(powerState); }
private async void Client_DeviceDiscovered(object sender, LifxClient.DeviceDiscoveryEventArgs e) { var bulb = e.Device as LightBulb; await client.SetDevicePowerStateAsync(bulb, true); //Turn bulb on // await client.SetColorAsync(bulb, red, 2700); //Set color to Red and 2700K Temperature // LightBulb bulb, // UInt16 hue, // UInt16 saturation, // UInt16 brightness, // UInt16 kelvin, // TimeSpan transitionDuration await client.SetColorAsync(bulb, (ushort)hue, (ushort)sat, (ushort)brightness, 2700, new System.TimeSpan(0, 0, (int)duration) ); }