Skip to content

Commit

Permalink
Add transition for lights (#21)
Browse files Browse the repository at this point in the history
* Remove redundant project from csproj

* Add config of light transition

---------

Co-authored-by: x00Pavel <[email protected]>
  • Loading branch information
x00Pavel and PavelVeeamer authored Oct 13, 2023
1 parent a9436f6 commit d05ce18
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 6 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
1 change: 0 additions & 1 deletion src/Extensions/Mapping/Mapping.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
<ItemGroup>
<ProjectReference Include="..\..\Automations\LightAutomation\LightAutomation.csproj" />
<ProjectReference Include="..\..\FSM\LightFsm\LightFsm.csproj" />
<ProjectReference Include="..\LightAutomation\LightAutomation.csproj" />
</ItemGroup>

</Project>
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 d05ce18

Please sign in to comment.