Turn off alarm first so it doesn't override
This commit is contained in:
parent
953abc5998
commit
3e33e489aa
1 changed files with 8 additions and 5 deletions
|
|
@ -59,8 +59,11 @@ let internal createOrUpdateNightLightState
|
||||||
let internal withStateFor (light: Light) (state: State) (oldNightLightState: NightLightState) =
|
let internal withStateFor (light: Light) (state: State) (oldNightLightState: NightLightState) =
|
||||||
let oldState = oldNightLightState.LightToState[light]
|
let oldState = oldNightLightState.LightToState[light]
|
||||||
|
|
||||||
{ oldNightLightState with
|
createOrUpdateNightLightState
|
||||||
LightToState = Map.add light { oldState with State = state } oldNightLightState.LightToState }
|
oldNightLightState.Time
|
||||||
|
oldNightLightState.Alarm
|
||||||
|
(Map.add light { oldState with State = state } oldNightLightState.LightToState
|
||||||
|
|> Some)
|
||||||
|
|
||||||
let internal withStateForRemoteControlledLights (state: State) (oldNightLightState: NightLightState) =
|
let internal withStateForRemoteControlledLights (state: State) (oldNightLightState: NightLightState) =
|
||||||
lights
|
lights
|
||||||
|
|
@ -101,16 +104,16 @@ type NightLightStateMachine private (maybeState: NightLightState option) =
|
||||||
| ButtonPress action ->
|
| ButtonPress action ->
|
||||||
let newNightLightState =
|
let newNightLightState =
|
||||||
match action with
|
match action with
|
||||||
| PressedOn -> currentState |> withStateForRemoteControlledLights On
|
| PressedOn -> currentState |> withAlarmOff |> withStateForRemoteControlledLights On
|
||||||
| PressedOff -> currentState |> withStateForRemoteControlledLights Off
|
| PressedOff -> currentState |> withAlarmOff |> withStateForRemoteControlledLights Off
|
||||||
| PressedLeft ->
|
| PressedLeft ->
|
||||||
let lightThatShouldBeOn =
|
let lightThatShouldBeOn =
|
||||||
lights |> Seq.find (fun light -> light.ControlledWithRemote = RemoteLeft)
|
lights |> Seq.find (fun light -> light.ControlledWithRemote = RemoteLeft)
|
||||||
|
|
||||||
currentState
|
currentState
|
||||||
|
|> withAlarmOff
|
||||||
|> withStateForRemoteControlledLights Off
|
|> withStateForRemoteControlledLights Off
|
||||||
|> withStateFor lightThatShouldBeOn On
|
|> withStateFor lightThatShouldBeOn On
|
||||||
|> withAlarmOff
|
|
||||||
|
|
||||||
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