From 3e33e489aadc203432c0f8fc84934c6c5a183fc8 Mon Sep 17 00:00:00 2001 From: Sven van Heugten Date: Sat, 17 Jan 2026 17:44:33 +0100 Subject: [PATCH] Turn off alarm first so it doesn't override --- NightLight.Core/NightLightStateMachine.fs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/NightLight.Core/NightLightStateMachine.fs b/NightLight.Core/NightLightStateMachine.fs index 23fb989..a91b4be 100644 --- a/NightLight.Core/NightLightStateMachine.fs +++ b/NightLight.Core/NightLightStateMachine.fs @@ -59,8 +59,11 @@ let internal createOrUpdateNightLightState let internal withStateFor (light: Light) (state: State) (oldNightLightState: NightLightState) = let oldState = oldNightLightState.LightToState[light] - { oldNightLightState with - LightToState = Map.add light { oldState with State = state } oldNightLightState.LightToState } + createOrUpdateNightLightState + oldNightLightState.Time + oldNightLightState.Alarm + (Map.add light { oldState with State = state } oldNightLightState.LightToState + |> Some) let internal withStateForRemoteControlledLights (state: State) (oldNightLightState: NightLightState) = lights @@ -101,16 +104,16 @@ type NightLightStateMachine private (maybeState: NightLightState option) = | ButtonPress action -> let newNightLightState = match action with - | PressedOn -> currentState |> withStateForRemoteControlledLights On - | PressedOff -> currentState |> withStateForRemoteControlledLights Off + | PressedOn -> currentState |> withAlarmOff |> withStateForRemoteControlledLights On + | PressedOff -> currentState |> withAlarmOff |> withStateForRemoteControlledLights Off | PressedLeft -> let lightThatShouldBeOn = lights |> Seq.find (fun light -> light.ControlledWithRemote = RemoteLeft) currentState + |> withAlarmOff |> withStateForRemoteControlledLights Off |> withStateFor lightThatShouldBeOn On - |> withAlarmOff NightLightStateMachine(Some newNightLightState), generateZigbeeCommandsForDifference (Some currentState) newNightLightState