Skip to content

Commit

Permalink
Add config of light transition
Browse files Browse the repository at this point in the history
  • Loading branch information
PavelVeeamer committed Oct 11, 2023
1 parent 2830602 commit 37a0537
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Automations/AutomationConfig/IFsmConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ public interface IFsmConfig<TFsmState> where TFsmState : Enum
public Func<TimeSpan> StopAtTimeFunc { get; }

public bool IsWorkingHours { get; }

public double Transition { get; set; }
}
4 changes: 2 additions & 2 deletions src/Extensions/LightExtensionMethods/LightExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ public static void TurnOn(this IEnumerable<ILightEntityCore> target)
target.CallService("turn_on");
}

public static void Toggle(this ILightEntityCore target, long? transition = null, long? brightnessPct = null)
public static void Toggle(this ILightEntityCore target, double? transition = null, long? brightnessPct = null)
{
target.CallService("toggle", new LightParameters { Transition = transition, BrightnessPct = brightnessPct});
}

public static void TurnOn(this IEnumerable<ILightEntityCore> target, long? transition = null, long? brightnessPct = null)
public static void TurnOn(this IEnumerable<ILightEntityCore> target, double? transition = null, long? brightnessPct = null)
{
target.CallService("toggle", new LightParameters { Transition = transition, BrightnessPct = brightnessPct});
}
Expand Down
2 changes: 1 addition & 1 deletion src/Extensions/LightExtensionMethods/LightParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace NetEntityAutomation.Extensions.LightExtensionMethods;
public record LightParameters
{
[JsonPropertyName("transition")]
public long? Transition { get; init; }
public double? Transition { get; init; }

[JsonPropertyName("brightness_pct")]
public long? BrightnessPct { get; init; }
Expand Down
2 changes: 2 additions & 0 deletions src/FSM/LightFsm/FsmConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ public bool IsWorkingHours
return now >= StartAtTimeFunc() || now <= StopAtTimeFunc();
}
}

public double Transition { get; set; } = 2.5;
}
2 changes: 1 addition & 1 deletion src/FSM/LightFsm/LightFsm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ protected void TurnOnLights()
}
else
{
Config.Lights.TurnOn(brightnessPct: 100);
Config.Lights.TurnOn(brightnessPct: 100, transition: Config.Transition);
}

Timer?.Dispose();
Expand Down

0 comments on commit 37a0537

Please sign in to comment.