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
|
(Map.add light { oldState with State = state } oldNightLightState.LightToState
|
||||||
|> Some)
|
|> 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) =
|
let internal withAlarmOff (oldNightLightState: NightLightState) =
|
||||||
createOrUpdateNightLightState oldNightLightState.Time false (Some oldNightLightState.LightToState)
|
createOrUpdateNightLightState oldNightLightState.Time false (Some oldNightLightState.LightToState)
|
||||||
|
|
||||||
|
|
@ -116,16 +111,21 @@ type NightLightStateMachine private (maybeState: NightLightState option) =
|
||||||
| ButtonPress action ->
|
| ButtonPress action ->
|
||||||
let newNightLightState =
|
let newNightLightState =
|
||||||
match action with
|
match action with
|
||||||
| PressedOn -> currentState |> withAlarmOff |> withStateForRemoteControlledLights On
|
| PressedOn ->
|
||||||
| PressedOff -> currentState |> withAlarmOff |> withStateForRemoteControlledLights Off
|
|
||||||
| PressedLeft ->
|
|
||||||
let lightThatShouldBeOn =
|
|
||||||
lights |> Seq.find (fun light -> light = SovrumNattduksbordlampa)
|
|
||||||
|
|
||||||
currentState
|
currentState
|
||||||
|> withAlarmOff
|
|> withAlarmOff
|
||||||
|> withStateForRemoteControlledLights Off
|
|> withStateFor VardagsrumFonsterlampa On
|
||||||
|> withStateFor lightThatShouldBeOn 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),
|
NightLightStateMachine(Some newNightLightState),
|
||||||
generateZigbeeCommandsForDifference (Some currentState) newNightLightState
|
generateZigbeeCommandsForDifference (Some currentState) newNightLightState
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue