Simplify a bit

This commit is contained in:
Sven van Heugten 2026-01-17 15:37:11 +01:00
parent 45210c30d4
commit 9de9aefcdf

View file

@ -46,9 +46,7 @@ type NightLightStateMachine private (maybeState: NightLightState option) =
oldLightToState oldLightToState
match event, maybeState with match event, maybeState with
| ReceivedZigbeeEvent payload, | ReceivedZigbeeEvent payload, Some state ->
Some { Time = time
LightToState = lightToState } ->
let! zigbeeEvent = parseZigbeeEvent payload |> Result.mapError ParseZigbeeEventError let! zigbeeEvent = parseZigbeeEvent payload |> Result.mapError ParseZigbeeEventError
return return
@ -58,27 +56,27 @@ type NightLightStateMachine private (maybeState: NightLightState option) =
this, this,
match maybeLight with match maybeLight with
| Some light -> generateZigbeeCommandsToFixLight lightToState[light] light | Some light -> generateZigbeeCommandsToFixLight state.LightToState[light] light
| None -> Seq.empty | None -> Seq.empty
| ButtonPress action -> | ButtonPress action ->
let newLightToState = let newLightToState =
match action with match action with
| PressedOn -> updateLightStateForRemoteControlledLights lightToState On | PressedOn -> updateLightStateForRemoteControlledLights state.LightToState On
| PressedOff -> updateLightStateForRemoteControlledLights lightToState Off | PressedOff -> updateLightStateForRemoteControlledLights state.LightToState Off
| PressedLeft -> | PressedLeft ->
let lightThatShouldBeOn = let lightThatShouldBeOn =
remoteControlledLights remoteControlledLights
|> Seq.find (fun light -> light.ControlledWithRemote = RemoteLeft) |> Seq.find (fun light -> light.ControlledWithRemote = RemoteLeft)
let oldState = lightToState[lightThatShouldBeOn] let oldState = state.LightToState[lightThatShouldBeOn]
updateLightStateForRemoteControlledLights lightToState Off updateLightStateForRemoteControlledLights state.LightToState Off
|> Map.add lightThatShouldBeOn { oldState with State = On } |> Map.add lightThatShouldBeOn { oldState with State = On }
NightLightStateMachine( NightLightStateMachine(
Some Some
<| { Time = time { state with
LightToState = newLightToState } LightToState = newLightToState }
), ),
remoteControlledLights remoteControlledLights
|> Seq.collect (fun light -> generateZigbeeCommandsToFixLight newLightToState[light] light) |> Seq.collect (fun light -> generateZigbeeCommandsToFixLight newLightToState[light] light)