Give every light its own type

This commit is contained in:
Sven van Heugten 2026-02-27 17:49:20 +01:00
parent dbb0389e61
commit 50c8a413a6
6 changed files with 72 additions and 50 deletions

View file

@ -52,7 +52,7 @@ type NightLightTests() =
&& time <= endOfAlarm
let scaledForAlarm light brightness =
if light.ControlledWithRemote <> NonRemote && alarm then
if (lightProps light).ControlledWithRemote <> NonRemote && alarm then
float brightness * ((time - startOfDay) / (endOfAlarm - startOfDay)) |> byte
else
brightness
@ -60,14 +60,14 @@ type NightLightTests() =
fakeHome.LightStates
|> Seq.forall (fun (light, state) ->
let maybeExpectedBrightness =
match light, state with
match (lightProps light).Bulb, state with
| _, Off -> None
| { Bulb = IkeaBulb }, On(_, White) -> Some 254uy
| { Bulb = IkeaBulb }, On(_, Yellow) -> Some 210uy
| { Bulb = IkeaBulb }, On(_, Red) -> Some 254uy
| { Bulb = PaulmannBulb }, On(_, White) -> Some 35uy
| { Bulb = PaulmannBulb }, On(_, Yellow) -> Some 35uy
| { Bulb = PaulmannBulb }, On(_, Red) -> Some 80uy
| IkeaBulb, On(_, White) -> Some 254uy
| IkeaBulb, On(_, Yellow) -> Some 210uy
| IkeaBulb, On(_, Red) -> Some 254uy
| PaulmannBulb, On(_, White) -> Some 35uy
| PaulmannBulb, On(_, Yellow) -> Some 35uy
| PaulmannBulb, On(_, Red) -> Some 80uy
|> Option.map (scaledForAlarm light)
let maybeActualBrightness =
@ -109,7 +109,7 @@ type NightLightTests() =
let allOff (ls: (Light * LightState) seq) = ls |> Seq.forall (snd >> _.IsOff)
let controlledBy remote ls =
ls |> Seq.filter (fst >> _.ControlledWithRemote >> (=) remote)
ls |> Seq.filter (fst >> lightProps >> _.ControlledWithRemote >> (=) remote)
let maybeLastRemoteInteraction = tryGetLastRemoteInteraction interactions