From 451d8b09f1592f0accc43c68663e7248c5df82d4 Mon Sep 17 00:00:00 2001 From: Sven van Heugten Date: Mon, 16 Mar 2026 19:56:02 +0100 Subject: [PATCH] Make the 'On' button cycle between lights --- NightLight.Core.Tests/NightLightTests.fs | 5 ++++- NightLight.Core/NightLightStateMachine.fs | 9 +++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/NightLight.Core.Tests/NightLightTests.fs b/NightLight.Core.Tests/NightLightTests.fs index cfbc25f..c1aab89 100644 --- a/NightLight.Core.Tests/NightLightTests.fs +++ b/NightLight.Core.Tests/NightLightTests.fs @@ -124,7 +124,10 @@ type NightLightTests() = (fun state interaction -> match state, interaction with | _, RemotePressedOffButton -> BothOff - | _, RemotePressedOnButton -> BothOn + | BothOff, RemotePressedOnButton -> BothOn + | BothOn, RemotePressedOnButton -> LeftOn + | LeftOn, RemotePressedOnButton -> RightOn + | RightOn, RemotePressedOnButton -> BothOn | _, RemotePressedLeftButton -> LeftOn) BothOn diff --git a/NightLight.Core/NightLightStateMachine.fs b/NightLight.Core/NightLightStateMachine.fs index 4ed8d9e..73a3169 100644 --- a/NightLight.Core/NightLightStateMachine.fs +++ b/NightLight.Core/NightLightStateMachine.fs @@ -95,8 +95,13 @@ type NightLightStateMachine private (maybeState: NightLightState option) = | PressedOn -> currentState |> withAlarmOff - |> withStateFor RightBedroomLamp On - |> withStateFor LeftBedroomLamp On + |> match + currentState.LightToManualState[LeftBedroomLamp], + currentState.LightToManualState[RightBedroomLamp] + with + | Off, _ -> withStateFor LeftBedroomLamp On >> withStateFor RightBedroomLamp On + | On, On -> withStateFor LeftBedroomLamp On >> withStateFor RightBedroomLamp Off + | On, Off -> withStateFor LeftBedroomLamp Off >> withStateFor RightBedroomLamp On | PressedOff -> currentState |> withAlarmOff