Make the Left and Right button behave the same way

This commit is contained in:
Sven van Heugten 2026-03-16 19:58:53 +01:00
parent 451d8b09f1
commit 5d8406d8ad
4 changed files with 8 additions and 11 deletions

View file

@ -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

View file

@ -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 ]

View file

@ -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 =

View file

@ -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