public async Task Transition(AppLightState target, LightCommand command, DateTime currentTime, bool reset) { if (reset) { this.lights.Reset(); } await Refresh(currentTime); PrintScheduled(); var commandLights = this.lights.SelectLightsToControl(); commandLights = commandLights.Filter(target); logger.LogCommand(commandLights, target); var commandIds = commandLights.Select(x => x.Properties.Id).ToArray(); foreach (var light in this.lights.Values) { if (commandIds.Any(i => i == light.Properties.Id)) { light.ExecuteCommand(command, currentTime); } else { light.ExecuteInstantaneousCommand(command); } } if (commandIds.Length > 0) { await client.SendCommandAsync(command, commandIds); } logger.LogUpdate(this.lights.Values); return; }
public static LightCommand ToCommand(this AppLightState expectedLight) { switch (expectedLight.Colour.Mode) { case ColourMode.XY: return(new LightCommand { Brightness = expectedLight.Brightness, ColorCoordinates = expectedLight.Colour.ColourCoordinates, }); case ColourMode.CT: return(new LightCommand { Brightness = expectedLight.Brightness, ColorTemperature = expectedLight.Colour.ColourTemperature, }); case ColourMode.HS: case ColourMode.Other: case ColourMode.None: default: throw new NotImplementedException(); } }
public AppLightState TargetLightState(DateTime currentTime) { var colourTemperatures = appOptionsDelegate.CurrentValue.ColourTemperature; var target = (currentTime <= transitionTimes.Day || currentTime >= transitionTimes.Night) ? colourTemperatures.Night : colourTemperatures.Day; var colour = new Colour(target); var targetLight = new AppLightState(colour); logger.LogDebug($"Transition target lightstate: {targetLight}"); return(targetLight); }
public static bool ColourEquals(this State @this, AppLightState expectedLight) { if (expectedLight.Colour.Mode != @this.ColorMode.ToColourMode()) { return(false); } switch (expectedLight.Colour.Mode) { case ColourMode.XY: return(ExtensionMethods.ArrayEquals(expectedLight.Colour.ColourCoordinates, @this.ColorCoordinates)); case ColourMode.CT: return(expectedLight.Colour.ColourTemperature == @this.ColorTemperature); default: //return this.Hue == lightState.Hue && this.Saturation == lightState.Saturation; throw new NotImplementedException(); } }
private LightCommand CreateAutoCommand(AppLightState light, TimeSpan?duration, bool resumeControl) { LightCommand command; if (resumeControl) { command = new LightCommand { Brightness = 254, ColorTemperature = light.Colour.ColourTemperature, TransitionTime = duration }; } else { command = new LightCommand { ColorTemperature = light.Colour.ColourTemperature, TransitionTime = duration }; } return(command); }
public static void LogCommand <T>(this ILogger <T> logger, IEnumerable <LightControlPair> commandLights, AppLightState target) { if (commandLights.Any()) { logger.LogInformation($"Sending command to lights:"); foreach (var light in commandLights) { logger.LogInformation($"ID: {light.Properties.Id} Name: {light.Properties.Name} | from: {light.ExpectedLight} | to: {target}"); } } }
public static LightControlPair[] Filter(this LightControlPair[] commandLights, AppLightState targetState) { var filtered = new List <LightControlPair>(); foreach (var light in commandLights) { if (!light.ExpectedLight.Equals(targetState)) { filtered.Add(light); } } return(filtered.ToArray()); }