Add tests for colors

This commit is contained in:
Sven van Heugten 2026-01-04 10:50:18 +01:00
parent 7125fee28e
commit 48aaabde3b
2 changed files with 45 additions and 9 deletions

View file

@ -44,6 +44,8 @@ type FakeLight(light: Light) =
color <- newColor
type FakeHome(now: DateTime) =
let mutable time = now
let mutable nightLightStateMachine = NightLightStateMachine now
let assertIsOkAndGet result =
@ -93,6 +95,8 @@ type FakeHome(now: DateTime) =
commands |> Seq.iter processCommand
nightLightStateMachine <- newState
member _.Time = time
member _.LightStates = friendlyNameToFakeLight.Values |> Seq.map _.LightWithState
member _.Interact(interaction: Interaction) =
@ -109,4 +113,23 @@ type FakeHome(now: DateTime) =
|> ReceivedZigbeeEvent
|> sendEvent
| HumanInteraction(LightTurnedOff light) -> friendlyNameToFakeLight[light.FriendlyName].TurnOff()
| TimeChanged time -> time |> Event.TimeChanged |> sendEvent
| TimeChanged newTime ->
time <- newTime
newTime |> Event.TimeChanged |> sendEvent
type FakeHome with
member this.Interact(interactions: Interaction seq) = interactions |> Seq.iter this.Interact
member this.ForAllLightsThatAreOn condition =
this.LightStates
|> Seq.choose (fun (light, state) ->
match state with
| On(brightness, color) -> Some(light, brightness, color)
| Off -> None)
|> Seq.forall condition
member this.IsDay() =
this.Time.TimeOfDay >= TimeSpan.FromHours 5.5
&& this.Time.TimeOfDay < TimeSpan.FromHours 20.5
member this.IsNight() = not (this.IsDay())