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 =
|
type internal NightLightState =
|
||||||
{ Time: DateTime
|
{ Time: DateTime
|
||||||
|
Alarm: bool
|
||||||
LightToState: Map<Light, LightState> }
|
LightToState: Map<Light, LightState> }
|
||||||
|
|
||||||
let internal withStateFor (light: Light) (state: State) (oldNightLightState: NightLightState) =
|
let internal withStateFor (light: Light) (state: State) (oldNightLightState: NightLightState) =
|
||||||
|
|
@ -37,6 +38,10 @@ let internal withStateForRemoteControlledLights (state: State) (oldNightLightSta
|
||||||
remoteControlledLights
|
remoteControlledLights
|
||||||
|> Seq.fold (fun acc light -> acc |> withStateFor light state) oldNightLightState
|
|> 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) =
|
let internal generateZigbeeCommandsForDifference (maybeBefore: NightLightState option) (after: NightLightState) =
|
||||||
after.LightToState
|
after.LightToState
|
||||||
|> Seq.collect (fun (KeyValue(light, newState)) ->
|
|> Seq.collect (fun (KeyValue(light, newState)) ->
|
||||||
|
|
@ -78,6 +83,7 @@ type NightLightStateMachine private (maybeState: NightLightState option) =
|
||||||
currentState
|
currentState
|
||||||
|> 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
|
||||||
|
|
@ -90,6 +96,10 @@ type NightLightStateMachine private (maybeState: NightLightState option) =
|
||||||
|
|
||||||
maybePreviousPartOfDay <> Some Day && newPartOfDay = Day
|
maybePreviousPartOfDay <> Some Day && newPartOfDay = Day
|
||||||
|
|
||||||
|
let alarm =
|
||||||
|
maybeCurrentState |> Option.map _.Alarm |> Option.defaultValue false
|
||||||
|
|| newDayStarted
|
||||||
|
|
||||||
let newLightToState =
|
let newLightToState =
|
||||||
lights
|
lights
|
||||||
|> Seq.map (fun light ->
|
|> Seq.map (fun light ->
|
||||||
|
|
@ -102,7 +112,7 @@ type NightLightStateMachine private (maybeState: NightLightState option) =
|
||||||
|> Option.map _.LightToState[light].State
|
|> Option.map _.LightToState[light].State
|
||||||
|> Option.defaultValue On
|
|> Option.defaultValue On
|
||||||
|
|
||||||
let newState = if newDayStarted then On else previousState
|
let newState = if alarm then On else previousState
|
||||||
|
|
||||||
light,
|
light,
|
||||||
{ Color = color
|
{ Color = color
|
||||||
|
|
@ -112,6 +122,7 @@ type NightLightStateMachine private (maybeState: NightLightState option) =
|
||||||
|
|
||||||
let newNightLightState =
|
let newNightLightState =
|
||||||
{ Time = newTime
|
{ Time = newTime
|
||||||
|
Alarm = alarm
|
||||||
LightToState = newLightToState }
|
LightToState = newLightToState }
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue