Introduce a global remoteControlledLights value

This commit is contained in:
Sven van Heugten 2026-01-14 19:55:58 +01:00
parent 2950b21488
commit 0d21e81b82
3 changed files with 8 additions and 14 deletions

View file

@ -15,25 +15,18 @@ type ArbitraryNonRemotelyControlledLight =
type ArbitraryLeftRemotelyControlledLight =
static member Light() =
lights
remoteControlledLights
|> Seq.filter _.ControlledWithRemote.IsRemoteLeft
|> Gen.elements
|> Arb.fromGen
type ArbitraryRightRemotelyControlledLight =
static member Light() =
lights
remoteControlledLights
|> Seq.filter _.ControlledWithRemote.IsRemoteRight
|> Gen.elements
|> Arb.fromGen
type ArbitraryRemotelyControlledLight =
static member Light() =
lights
|> Seq.filter (fun light ->
match light.ControlledWithRemote with
| RemoteLeft -> true
| RemoteRight -> true
| NonRemote -> false)
|> Gen.elements
|> Arb.fromGen
remoteControlledLights |> Gen.elements |> Arb.fromGen

View file

@ -73,4 +73,7 @@ let lights =
Bulb = IkeaBulb
ControlledWithRemote = RemoteLeft } ]
let remoteControlledLights =
lights |> Seq.filter (not << _.ControlledWithRemote.IsNonRemote)
let remoteControlFriendlyName = DeviceFriendlyName "Fjärrkontroll"

View file

@ -33,9 +33,6 @@ type NightLightStateMachine private (maybeTime: DateTime option, lightToState: M
result {
let maybePartOfDay = maybeTime |> Option.map getPartOfDay
let remoteControlledLights =
lights |> Seq.filter (not << _.ControlledWithRemote.IsNonRemote)
let updateLightStateForRemoteControlledLights desiredLightState =
remoteControlledLights
|> Seq.fold (fun acc key -> Map.add key desiredLightState acc) lightToState
@ -61,7 +58,8 @@ type NightLightStateMachine private (maybeTime: DateTime option, lightToState: M
| PressedLeft ->
updateLightStateForRemoteControlledLights Off
|> Map.add
(lights |> Seq.find (fun light -> light.ControlledWithRemote = RemoteLeft))
(remoteControlledLights
|> Seq.find (fun light -> light.ControlledWithRemote = RemoteLeft))
On
NightLightStateMachine(maybeTime, newLightToState),