Get rid of withStateForRemoteControlledLights
This commit is contained in:
parent
3855439d82
commit
00242e16ad
1 changed files with 13 additions and 13 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue