Rewrite construction of newLightToState
This commit is contained in:
parent
4d8fc44bee
commit
78b57258c1
1 changed files with 13 additions and 8 deletions
|
|
@ -85,14 +85,19 @@ type NightLightStateMachine private (maybeState: NightLightState option) =
|
||||||
maybePreviousPartOfDay <> Some newPartOfDay
|
maybePreviousPartOfDay <> Some newPartOfDay
|
||||||
|
|
||||||
let newLightToState =
|
let newLightToState =
|
||||||
maybeState
|
lights
|
||||||
|> Option.map _.LightToState
|
|> Seq.map (fun light ->
|
||||||
|> Option.map (fun lightToState ->
|
let previousState =
|
||||||
if partOfDayChanged && newPartOfDay = Day then
|
maybeState |> Option.map _.LightToState[light] |> Option.defaultValue On
|
||||||
updateLightStateForRemoteControlledLights lightToState On
|
|
||||||
else
|
let newState =
|
||||||
lightToState)
|
if partOfDayChanged && newPartOfDay = Day then
|
||||||
|> Option.defaultValue (lights |> Seq.map (fun light -> light, On) |> Map.ofSeq)
|
On
|
||||||
|
else
|
||||||
|
previousState
|
||||||
|
|
||||||
|
light, newState)
|
||||||
|
|> Map.ofSeq
|
||||||
|
|
||||||
let newState =
|
let newState =
|
||||||
NightLightStateMachine(
|
NightLightStateMachine(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue