Implement the Right button on the bedroom remote

This commit is contained in:
Sven van Heugten 2026-02-27 19:09:13 +01:00
parent b9fc8bfaea
commit d3a00b8a77
5 changed files with 74 additions and 64 deletions

View file

@ -52,7 +52,11 @@ let internal createOrUpdateNightLightState
brightness.Scale(getAlarmWeight time)
else
brightness
State = if alarm then On else previousState })
State =
if alarm && (light = RightBedroomLamp || light = LeftBedroomLamp) then
On
else
previousState })
|> Map.ofSeq
{ Time = time
@ -117,6 +121,11 @@ type NightLightStateMachine private (maybeState: NightLightState option) =
|> withAlarmOff
|> withStateFor RightBedroomLamp Off
|> withStateFor LeftBedroomLamp On
| PressedRight ->
currentState
|> withAlarmOff
|> withStateFor LivingRoomWallLamp Off
|> withStateFor LivingRoomFloorLamp Off
NightLightStateMachine(Some newNightLightState),
generateZigbeeCommandsForDifference (Some currentState) newNightLightState

View file

@ -8,6 +8,7 @@ type Action =
| PressedOn
| PressedOff
| PressedLeft
| PressedRight
type ZigbeeEvent =
| DeviceAnnounce of DeviceFriendlyName
@ -37,6 +38,7 @@ let parseZigbeeEvent (message: Message) =
| Some(JsonValue.String "on") -> Ok(ButtonPress PressedOn)
| Some(JsonValue.String "off") -> Ok(ButtonPress PressedOff)
| Some(JsonValue.String "arrow_left_click") -> Ok(ButtonPress PressedLeft)
| Some(JsonValue.String "arrow_right_click") -> Ok(ButtonPress PressedRight)
| Some _ -> Error InvalidActionField
| None -> Error MissingActionField
| _ -> return! Error <| UnknownTopic message.Topic