From 5d8406d8ad1738ce1f55f45f4cac73e4ac6a122a Mon Sep 17 00:00:00 2001 From: Sven van Heugten Date: Mon, 16 Mar 2026 19:58:53 +0100 Subject: [PATCH] Make the Left and Right button behave the same way --- NightLight.Core.Tests/FakeHome.fs | 4 ++-- NightLight.Core.Tests/InteractionListGenerators.fs | 5 +++-- NightLight.Core.Tests/NightLightTests.fs | 4 ++-- NightLight.Core/NightLightStateMachine.fs | 6 +----- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/NightLight.Core.Tests/FakeHome.fs b/NightLight.Core.Tests/FakeHome.fs index f7042b7..a1c64bc 100644 --- a/NightLight.Core.Tests/FakeHome.fs +++ b/NightLight.Core.Tests/FakeHome.fs @@ -9,9 +9,9 @@ open FSharp.Data type BedroomControllingRemoteInteraction = | RemotePressedOnButton | RemotePressedOffButton - | RemotePressedLeftButton type LivingRoomControllingRemoteAction = + | RemotePressedLeftButton | RemotePressedRightButton | LivingRoomRemotePressedOnButton | LivingRoomRemotePressedOffButton @@ -138,7 +138,7 @@ type FakeHome() = Payload = @"{ ""action"": ""off"" }" } |> ReceivedZigbeeEvent |> onEventPublished.Trigger - | BedroomControllingRemoteInteraction RemotePressedLeftButton -> + | LivingRoomControllingRemoteInteraction RemotePressedLeftButton -> { Topic = $"zigbee2mqtt/{remoteControlFriendlyName.Get}" Payload = @"{ ""action"": ""arrow_left_click"" }" } |> ReceivedZigbeeEvent diff --git a/NightLight.Core.Tests/InteractionListGenerators.fs b/NightLight.Core.Tests/InteractionListGenerators.fs index cdd72d1..e8cbdf8 100644 --- a/NightLight.Core.Tests/InteractionListGenerators.fs +++ b/NightLight.Core.Tests/InteractionListGenerators.fs @@ -37,11 +37,12 @@ let private genHumanInteraction = let private genRemoteInteraction = Gen.oneof - [ Gen.elements [ RemotePressedOnButton; RemotePressedOffButton; RemotePressedLeftButton ] + [ Gen.elements [ RemotePressedOnButton; RemotePressedOffButton ] |> Gen.map BedroomControllingRemoteInteraction Gen.elements - [ RemotePressedRightButton + [ RemotePressedLeftButton + RemotePressedRightButton LivingRoomRemotePressedOnButton LivingRoomRemotePressedOffButton ] |> Gen.map LivingRoomControllingRemoteInteraction ] diff --git a/NightLight.Core.Tests/NightLightTests.fs b/NightLight.Core.Tests/NightLightTests.fs index c1aab89..7ad546b 100644 --- a/NightLight.Core.Tests/NightLightTests.fs +++ b/NightLight.Core.Tests/NightLightTests.fs @@ -110,6 +110,7 @@ type NightLightTests() = |> Seq.fold (fun state interaction -> match interaction with + | RemotePressedLeftButton -> not state | RemotePressedRightButton -> not state | LivingRoomRemotePressedOnButton -> true | LivingRoomRemotePressedOffButton -> false) @@ -127,8 +128,7 @@ type NightLightTests() = | BothOff, RemotePressedOnButton -> BothOn | BothOn, RemotePressedOnButton -> LeftOn | LeftOn, RemotePressedOnButton -> RightOn - | RightOn, RemotePressedOnButton -> BothOn - | _, RemotePressedLeftButton -> LeftOn) + | RightOn, RemotePressedOnButton -> BothOn) BothOn let isExpectedOn light = diff --git a/NightLight.Core/NightLightStateMachine.fs b/NightLight.Core/NightLightStateMachine.fs index 73a3169..1c75b0b 100644 --- a/NightLight.Core/NightLightStateMachine.fs +++ b/NightLight.Core/NightLightStateMachine.fs @@ -107,11 +107,7 @@ type NightLightStateMachine private (maybeState: NightLightState option) = |> withAlarmOff |> withStateFor RightBedroomLamp Off |> withStateFor LeftBedroomLamp Off - | PressedLeft -> - currentState - |> withAlarmOff - |> withStateFor RightBedroomLamp Off - |> withStateFor LeftBedroomLamp On + | PressedLeft | PressedRight -> currentState |> withInvertedStateFor LivingRoomWallLamp