From 78b57258c124ef6e1000503ba6da6d444969539c Mon Sep 17 00:00:00 2001 From: Sven van Heugten Date: Sat, 17 Jan 2026 15:23:13 +0100 Subject: [PATCH] Rewrite construction of newLightToState --- NightLight.Core/NightLightStateMachine.fs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/NightLight.Core/NightLightStateMachine.fs b/NightLight.Core/NightLightStateMachine.fs index f176d70..0d20231 100644 --- a/NightLight.Core/NightLightStateMachine.fs +++ b/NightLight.Core/NightLightStateMachine.fs @@ -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(