Get rid of NightLightStateMachine in the tests

This commit is contained in:
Sven van Heugten 2026-01-04 10:23:36 +01:00
parent bd550bfcd9
commit 285874777a
3 changed files with 17 additions and 41 deletions

View file

@ -3,6 +3,7 @@ namespace NightLight.Core.Tests
open System
open System.Text.RegularExpressions
open NightLight.Core.Models
open NightLight.Core.Core
open FsToolkit.ErrorHandling
open FSharp.Data
@ -33,7 +34,12 @@ type FakeLight(light: Light) =
brightness <- newBrightness
type FakeHome(now: DateTime) =
let nightLightStateMachine = NightLightStateMachine now
let mutable nightLightStateMachine = State now
let assertIsOkAndGet result =
match result with
| Ok value -> value
| Error error -> failwith $"Expected Ok, got Error {error}"
let friendlyNameToFakeLight =
lights
@ -57,6 +63,13 @@ type FakeHome(now: DateTime) =
}
|> ignore
let sendEvent event =
let newState, commands =
event |> nightLightStateMachine.OnEventReceived |> assertIsOkAndGet
commands |> Seq.iter processCommand
nightLightStateMachine <- newState
member _.LightStates = friendlyNameToFakeLight.Values |> Seq.map _.LightWithState
member _.Interact(interaction: Interaction) =
@ -70,9 +83,7 @@ type FakeHome(now: DateTime) =
""type"": ""device_announce"",
""data"": {{ ""friendly_name"": ""{light.FriendlyName}"" }}
}}" }
|> nightLightStateMachine.SendMessage
|> ReceivedZigbeeEvent
|> sendEvent
| HumanInteraction(LightTurnedOff light) -> friendlyNameToFakeLight[light.FriendlyName].TurnOff()
| TimeChanged time -> nightLightStateMachine.ChangeTime time
nightLightStateMachine.TransmittedCommands |> Seq.iter processCommand
nightLightStateMachine.ClearTransmittedCommands()
| TimeChanged time -> time |> Event.TimeChanged |> sendEvent