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
match event, maybeState with
| ReceivedZigbeeEvent payload,
Some { Time = time
LightToState = lightToState } ->
| ReceivedZigbeeEvent payload, Some state ->
let! zigbeeEvent = parseZigbeeEvent payload |> Result.mapError ParseZigbeeEventError
return
@ -58,26 +56,26 @@ type NightLightStateMachine private (maybeState: NightLightState option) =
this,
match maybeLight with
| Some light -> generateZigbeeCommandsToFixLight lightToState[light] light
| Some light -> generateZigbeeCommandsToFixLight state.LightToState[light] light
| None -> Seq.empty
| ButtonPress action ->
let newLightToState =
match action with
| PressedOn -> updateLightStateForRemoteControlledLights lightToState On
| PressedOff -> updateLightStateForRemoteControlledLights lightToState Off
| PressedOn -> updateLightStateForRemoteControlledLights state.LightToState On
| PressedOff -> updateLightStateForRemoteControlledLights state.LightToState Off
| PressedLeft ->
let lightThatShouldBeOn =
remoteControlledLights
|> 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 }
NightLightStateMachine(
Some
<| { Time = time
{ state with
LightToState = newLightToState }
),
remoteControlledLights