Simplify a bit
This commit is contained in:
parent
45210c30d4
commit
9de9aefcdf
1 changed files with 8 additions and 10 deletions
|
|
@ -46,9 +46,7 @@ type NightLightStateMachine private (maybeState: NightLightState option) =
|
||||||
oldLightToState
|
oldLightToState
|
||||||
|
|
||||||
match event, maybeState with
|
match event, maybeState with
|
||||||
| ReceivedZigbeeEvent payload,
|
| ReceivedZigbeeEvent payload, Some state ->
|
||||||
Some { Time = time
|
|
||||||
LightToState = lightToState } ->
|
|
||||||
let! zigbeeEvent = parseZigbeeEvent payload |> Result.mapError ParseZigbeeEventError
|
let! zigbeeEvent = parseZigbeeEvent payload |> Result.mapError ParseZigbeeEventError
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
@ -58,26 +56,26 @@ type NightLightStateMachine private (maybeState: NightLightState option) =
|
||||||
|
|
||||||
this,
|
this,
|
||||||
match maybeLight with
|
match maybeLight with
|
||||||
| Some light -> generateZigbeeCommandsToFixLight lightToState[light] light
|
| Some light -> generateZigbeeCommandsToFixLight state.LightToState[light] light
|
||||||
| None -> Seq.empty
|
| None -> Seq.empty
|
||||||
| ButtonPress action ->
|
| ButtonPress action ->
|
||||||
let newLightToState =
|
let newLightToState =
|
||||||
match action with
|
match action with
|
||||||
| PressedOn -> updateLightStateForRemoteControlledLights lightToState On
|
| PressedOn -> updateLightStateForRemoteControlledLights state.LightToState On
|
||||||
| PressedOff -> updateLightStateForRemoteControlledLights lightToState Off
|
| PressedOff -> updateLightStateForRemoteControlledLights state.LightToState Off
|
||||||
| PressedLeft ->
|
| PressedLeft ->
|
||||||
let lightThatShouldBeOn =
|
let lightThatShouldBeOn =
|
||||||
remoteControlledLights
|
remoteControlledLights
|
||||||
|> Seq.find (fun light -> light.ControlledWithRemote = RemoteLeft)
|
|> Seq.find (fun light -> light.ControlledWithRemote = RemoteLeft)
|
||||||
|
|
||||||
let oldState = lightToState[lightThatShouldBeOn]
|
let oldState = state.LightToState[lightThatShouldBeOn]
|
||||||
|
|
||||||
updateLightStateForRemoteControlledLights lightToState Off
|
updateLightStateForRemoteControlledLights state.LightToState Off
|
||||||
|> Map.add lightThatShouldBeOn { oldState with State = On }
|
|> Map.add lightThatShouldBeOn { oldState with State = On }
|
||||||
|
|
||||||
NightLightStateMachine(
|
NightLightStateMachine(
|
||||||
Some
|
Some
|
||||||
<| { Time = time
|
{ state with
|
||||||
LightToState = newLightToState }
|
LightToState = newLightToState }
|
||||||
),
|
),
|
||||||
remoteControlledLights
|
remoteControlledLights
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue