Rewrite construction of newLightToState

This commit is contained in:
Sven van Heugten 2026-01-17 15:23:13 +01:00
parent 4d8fc44bee
commit 78b57258c1

View file

@ -85,14 +85,19 @@ type NightLightStateMachine private (maybeState: NightLightState option) =
maybePreviousPartOfDay <> Some newPartOfDay
let newLightToState =
maybeState
|> Option.map _.LightToState
|> Option.map (fun lightToState ->
if partOfDayChanged && newPartOfDay = Day then
updateLightStateForRemoteControlledLights lightToState On
else
lightToState)
|> Option.defaultValue (lights |> Seq.map (fun light -> light, On) |> Map.ofSeq)
lights
|> Seq.map (fun light ->
let previousState =
maybeState |> Option.map _.LightToState[light] |> Option.defaultValue On
let newState =
if partOfDayChanged && newPartOfDay = Day then
On
else
previousState
light, newState)
|> Map.ofSeq
let newState =
NightLightStateMachine(