Remember if the alarm is on
This commit is contained in:
parent
b55e48ab22
commit
998e3a94fc
1 changed files with 12 additions and 1 deletions
|
|
@ -25,6 +25,7 @@ let internal generateZigbeeCommandsToFixLight state (light: Light) =
|
|||
|
||||
type internal NightLightState =
|
||||
{ Time: DateTime
|
||||
Alarm: bool
|
||||
LightToState: Map<Light, LightState> }
|
||||
|
||||
let internal withStateFor (light: Light) (state: State) (oldNightLightState: NightLightState) =
|
||||
|
|
@ -37,6 +38,10 @@ let internal withStateForRemoteControlledLights (state: State) (oldNightLightSta
|
|||
remoteControlledLights
|
||||
|> Seq.fold (fun acc light -> acc |> withStateFor light state) oldNightLightState
|
||||
|
||||
let internal withAlarmOff (oldNightLightState: NightLightState) =
|
||||
{ oldNightLightState with
|
||||
Alarm = false }
|
||||
|
||||
let internal generateZigbeeCommandsForDifference (maybeBefore: NightLightState option) (after: NightLightState) =
|
||||
after.LightToState
|
||||
|> Seq.collect (fun (KeyValue(light, newState)) ->
|
||||
|
|
@ -78,6 +83,7 @@ type NightLightStateMachine private (maybeState: NightLightState option) =
|
|||
currentState
|
||||
|> withStateForRemoteControlledLights Off
|
||||
|> withStateFor lightThatShouldBeOn On
|
||||
|> withAlarmOff
|
||||
|
||||
NightLightStateMachine(Some newNightLightState),
|
||||
generateZigbeeCommandsForDifference (Some currentState) newNightLightState
|
||||
|
|
@ -90,6 +96,10 @@ type NightLightStateMachine private (maybeState: NightLightState option) =
|
|||
|
||||
maybePreviousPartOfDay <> Some Day && newPartOfDay = Day
|
||||
|
||||
let alarm =
|
||||
maybeCurrentState |> Option.map _.Alarm |> Option.defaultValue false
|
||||
|| newDayStarted
|
||||
|
||||
let newLightToState =
|
||||
lights
|
||||
|> Seq.map (fun light ->
|
||||
|
|
@ -102,7 +112,7 @@ type NightLightStateMachine private (maybeState: NightLightState option) =
|
|||
|> Option.map _.LightToState[light].State
|
||||
|> Option.defaultValue On
|
||||
|
||||
let newState = if newDayStarted then On else previousState
|
||||
let newState = if alarm then On else previousState
|
||||
|
||||
light,
|
||||
{ Color = color
|
||||
|
|
@ -112,6 +122,7 @@ type NightLightStateMachine private (maybeState: NightLightState option) =
|
|||
|
||||
let newNightLightState =
|
||||
{ Time = newTime
|
||||
Alarm = alarm
|
||||
LightToState = newLightToState }
|
||||
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue