From 9f753daccc1fdb8efdb0ed90f79547efe92b7c49 Mon Sep 17 00:00:00 2001 From: Jasper Date: Thu, 8 Jan 2026 20:08:37 +0100 Subject: [PATCH] Implemented LightParametersThatTurnsOffAfter. --- .../LightPipelineContextExtensions.cs | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/CodeCasa.AutomationPipelines.Lights/Extensions/LightPipelineContextExtensions.cs diff --git a/src/CodeCasa.AutomationPipelines.Lights/Extensions/LightPipelineContextExtensions.cs b/src/CodeCasa.AutomationPipelines.Lights/Extensions/LightPipelineContextExtensions.cs new file mode 100644 index 0000000..0f27f5e --- /dev/null +++ b/src/CodeCasa.AutomationPipelines.Lights/Extensions/LightPipelineContextExtensions.cs @@ -0,0 +1,50 @@ +using CodeCasa.Lights; +using System.Reactive.Concurrency; +using CodeCasa.AutomationPipelines.Lights.Context; +using CodeCasa.AutomationPipelines.Lights.Nodes; +using Microsoft.Extensions.DependencyInjection; + +namespace CodeCasa.AutomationPipelines.Lights.Extensions +{ + /// + /// Extension methods for . + /// + public static class LightPipelineContextExtensions + { + /// + /// Creates a pipeline node that applies the specified light parameters and automatically turns off the light after a specified duration. + /// The timeout is not reset by any external events. + /// + /// The light pipeline context. + /// The light parameters to apply as a transition. + /// The duration after which the light should turn off. + /// A pipeline node that applies the light parameters and handles the turn-off behavior. + public static IPipelineNode LightParametersThatTurnsOffAfter(this ILightPipelineContext context, + LightParameters lightParameters, + TimeSpan timeSpan) + { + var scheduler = context.ServiceProvider.GetRequiredService(); + var innerNode = new StaticLightTransitionNode(lightParameters.AsTransition(), scheduler); + return innerNode.TurnOffAfter(timeSpan, scheduler); + } + + /// + /// Creates a pipeline node that applies the specified light parameters and automatically turns off the light after a specified duration. + /// The timeout can be reset when the observable emits a value. + /// + /// The type of elements emitted by the reset timer observable. + /// The light pipeline context. + /// The light parameters to apply as a transition. + /// The duration after which the light should turn off. + /// An observable that resets the turn-off timer when it emits. + /// A pipeline node that applies the light parameters and handles the turn-off behavior. + public static IPipelineNode LightParametersThatTurnsOffAfter(this ILightPipelineContext context, + LightParameters lightParameters, + TimeSpan timeSpan, IObservable resetTimerObservable) + { + var scheduler = context.ServiceProvider.GetRequiredService(); + var innerNode = new StaticLightTransitionNode(lightParameters.AsTransition(), scheduler); + return innerNode.TurnOffAfter(timeSpan, resetTimerObservable, scheduler); + } + } +}