private WizResult UpdateLight(WizParams wizParams, string lightId) { WizSocket socket = new WizSocket(); socket.GetSocket().EnableBroadcast = true; // This will enable sending to the broadcast address socket.GetSocket().ReceiveTimeout = 1000; // This will prevent the demo from running indefinitely WizHandle handle = new WizHandle(lightId, IPAddress.Broadcast); // MAC doesn't matter here WizState state = new WizState { Method = WizMethod.setPilot, Params = wizParams }; socket.SendTo(state, handle); WizResult pilot; while (true) { state = socket.ReceiveFrom(handle); pilot = state.Result; break; } return(pilot); }
private (string color, WizParams command, bool returnFunc) Handle(string presence, string lightId) { var props = _options.LightSettings.Hue.Statuses.GetType().GetProperties().ToList(); if (_options.LightSettings.Hue.UseActivityStatus) { props = props.Where(a => a.Name.ToLower().StartsWith("activity")).ToList(); } else { props = props.Where(a => a.Name.ToLower().StartsWith("availability")).ToList(); } string color = ""; string message; var command = new WizParams(); if (presence.Contains("#")) { // provided presence is actually a custom color color = presence; command.State = true; return(color, command, false); } foreach (var prop in props) { if (presence == prop.Name.Replace("Status", "").Replace("Availability", "").Replace("Activity", "")) { var value = (AvailabilityStatus)prop.GetValue(_options.LightSettings.Hue.Statuses); if (!value.Disabled) { command.State = true; color = value.Colour; return(color, command, false); } else { command.State = false; UpdateLight(command, lightId); message = $"Turning Hue Light {lightId} Off"; _logger.LogInformation(message); return(color, command, true); } } } return(color, command, false); }