-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLightTransitionReactiveNodeConfiguratorExtensions.Scene.cs
More file actions
89 lines (81 loc) · 4.85 KB
/
Copy pathLightTransitionReactiveNodeConfiguratorExtensions.Scene.cs
File metadata and controls
89 lines (81 loc) · 4.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using CodeCasa.AutomationPipelines.Lights.Cycle;
using CodeCasa.AutomationPipelines.Lights.ReactiveNode;
using CodeCasa.AutomationPipelines.Lights.Toggle;
using CodeCasa.Lights.NetDaemon;
using CodeCasa.Lights.NetDaemon.Scenes;
using NetDaemon.HassModel.Entities;
namespace CodeCasa.AutomationPipelines.Lights.NetDaemon.Extensions;
public static partial class LightTransitionReactiveNodeConfiguratorExtensions
{
// -------------------------------------------------------------------------
// On
// -------------------------------------------------------------------------
/// <summary>
/// Registers a trigger that applies light parameters from the given Home Assistant <paramref name="sceneEntity"/>
/// when the <paramref name="triggerObservable"/> emits a value.
/// The scene is fetched and cached via <see cref="LightSceneCacheService"/> on first use.
/// If the current light is not part of the scene, no state is applied.
/// </summary>
/// <typeparam name="T">The type of values emitted by the trigger observable.</typeparam>
/// <param name="configurator">The reactive node configurator.</param>
/// <param name="triggerObservable">The observable that triggers the scene application.</param>
/// <param name="sceneEntity">The scene entity whose light parameters will be applied.</param>
/// <returns>The configurator instance for method chaining.</returns>
public static ILightTransitionReactiveNodeConfigurator<NetDaemonLight> On<T>(
this ILightTransitionReactiveNodeConfigurator<NetDaemonLight> configurator,
IObservable<T> triggerObservable,
IEntityCore sceneEntity)
{
return configurator.On(triggerObservable, sp => SceneExtensionHelpers.GetSceneLightParameters(sp, sceneEntity));
}
// -------------------------------------------------------------------------
// AddToggle (with scene entries)
// -------------------------------------------------------------------------
/// <summary>
/// Adds a time-based toggle trigger that cycles through one or more Home Assistant scenes when triggered by <paramref name="triggerObservable"/>.
/// Quick consecutive triggers advance through all scenes sequentially. After a timeout period, the next trigger restarts from the beginning.
/// Scenes are fetched and cached via <see cref="LightSceneCacheService"/> on first use.
/// If the current light is not part of a scene, no state is applied for that step.
/// </summary>
/// <typeparam name="T">The type of values emitted by the trigger observable.</typeparam>
/// <param name="configurator">The reactive node configurator.</param>
/// <param name="triggerObservable">The observable that triggers toggling to the next scene.</param>
/// <param name="sceneEntities">The scene entities to toggle through.</param>
/// <returns>The configurator instance for method chaining.</returns>
public static ILightTransitionReactiveNodeConfigurator<NetDaemonLight> AddToggle<T>(
this ILightTransitionReactiveNodeConfigurator<NetDaemonLight> configurator,
IObservable<T> triggerObservable,
params IEntityCore[] sceneEntities)
{
return configurator.AddToggle(triggerObservable, c =>
{
foreach (var scene in sceneEntities)
c.AddScene(scene);
});
}
// -------------------------------------------------------------------------
// AddCycle (with scene entries)
// -------------------------------------------------------------------------
/// <summary>
/// Adds a state-based cycle trigger that rotates through one or more Home Assistant scenes when triggered by <paramref name="triggerObservable"/>.
/// The cycle advances based on the current light state. If the current state is not recognized, the cycle starts from the beginning.
/// Scenes are fetched and cached via <see cref="LightSceneCacheService"/> on first use.
/// If the current light is not part of a scene, no state is applied for that step.
/// </summary>
/// <typeparam name="T">The type of values emitted by the trigger observable.</typeparam>
/// <param name="configurator">The reactive node configurator.</param>
/// <param name="triggerObservable">The observable that triggers cycling to the next scene.</param>
/// <param name="sceneEntities">The scene entities to cycle through.</param>
/// <returns>The configurator instance for method chaining.</returns>
public static ILightTransitionReactiveNodeConfigurator<NetDaemonLight> AddCycle<T>(
this ILightTransitionReactiveNodeConfigurator<NetDaemonLight> configurator,
IObservable<T> triggerObservable,
params IEntityCore[] sceneEntities)
{
return configurator.AddCycle(triggerObservable, c =>
{
foreach (var scene in sceneEntities)
c.AddScene(scene);
});
}
}