Get rid of withStateForRemoteControlledLights

This commit is contained in:
Sven van Heugten 2026-02-27 18:03:39 +01:00
parent 3855439d82
commit 00242e16ad

View file

@ -77,11 +77,6 @@ let internal withStateFor (light: Light) (state: State) (oldNightLightState: Nig
(Map.add light { oldState with State = state } oldNightLightState.LightToState
|> Some)
let internal withStateForRemoteControlledLights (state: State) (oldNightLightState: NightLightState) =
lights
|> Seq.filter (fun light -> light = VardagsrumFonsterlampa || light = SovrumNattduksbordlampa)
|> Seq.fold (fun acc light -> acc |> withStateFor light state) oldNightLightState
let internal withAlarmOff (oldNightLightState: NightLightState) =
createOrUpdateNightLightState oldNightLightState.Time false (Some oldNightLightState.LightToState)
@ -116,16 +111,21 @@ type NightLightStateMachine private (maybeState: NightLightState option) =
| ButtonPress action ->
let newNightLightState =
match action with
| PressedOn -> currentState |> withAlarmOff |> withStateForRemoteControlledLights On
| PressedOff -> currentState |> withAlarmOff |> withStateForRemoteControlledLights Off
| PressedLeft ->
let lightThatShouldBeOn =
lights |> Seq.find (fun light -> light = SovrumNattduksbordlampa)
| PressedOn ->
currentState
|> withAlarmOff
|> withStateForRemoteControlledLights Off
|> withStateFor lightThatShouldBeOn On
|> withStateFor VardagsrumFonsterlampa On
|> withStateFor SovrumNattduksbordlampa On
| PressedOff ->
currentState
|> withAlarmOff
|> withStateFor VardagsrumFonsterlampa Off
|> withStateFor SovrumNattduksbordlampa Off
| PressedLeft ->
currentState
|> withAlarmOff
|> withStateFor VardagsrumFonsterlampa Off
|> withStateFor SovrumNattduksbordlampa On
NightLightStateMachine(Some newNightLightState),
generateZigbeeCommandsForDifference (Some currentState) newNightLightState