Reorganize types to prepare for unit testing

This commit is contained in:
Sven van Heugten 2026-01-03 20:03:18 +01:00
parent 5219abfb4b
commit 83b716a509
7 changed files with 52 additions and 62 deletions

View file

@ -1,34 +0,0 @@
module internal NightLight.Core.Configuration
open NightLight.Core.Moods
open NightLight.Core.Lights
let getDesiredColorAndBrightness bulb mood =
let white = ColorByCoordinates(0.3227, 0.329)
let yellow = ColorByTemperature 454
let red = ColorByCoordinates(0.6942, 0.2963)
match bulb, mood with
| IkeaBulb, White -> white, Brightness 254
| IkeaBulb, Yellow -> yellow, Brightness 210
| IkeaBulb, Red -> red, Brightness 254
| PaulmannBulb, White -> white, Brightness 35
| PaulmannBulb, Yellow -> yellow, Brightness 35
| PaulmannBulb, Red -> red, Brightness 80
let lights =
[ { FriendlyName = "Vardagsrum - Fönsterlampa"
Room = LivingRoom
Bulb = IkeaBulb }
{ FriendlyName = "Vardagsrum - Vägglampa"
Room = LivingRoom
Bulb = PaulmannBulb }
{ FriendlyName = "Vardagsrum - Golvlampa"
Room = LivingRoom
Bulb = PaulmannBulb }
{ FriendlyName = "Badrum - Taklampa"
Room = Bathroom
Bulb = IkeaBulb }
{ FriendlyName = "Sovrum - Nattduksbordlampa"
Room = Bedroom
Bulb = IkeaBulb } ]

View file

@ -5,8 +5,6 @@ open NightLight.Core.PartsOfDay
open NightLight.Core.ZigbeeEvents open NightLight.Core.ZigbeeEvents
open NightLight.Core.ZigbeeCommands open NightLight.Core.ZigbeeCommands
open NightLight.Core.Moods open NightLight.Core.Moods
open NightLight.Core.Lights
open NightLight.Core.Configuration
open FsToolkit.ErrorHandling open FsToolkit.ErrorHandling
let internal tryFindLight friendlyName = let internal tryFindLight friendlyName =

View file

@ -1,18 +0,0 @@
module internal NightLight.Core.Lights
open NightLight.Core.Moods
type Bulb =
| IkeaBulb
| PaulmannBulb
type Color =
| ColorByCoordinates of float * float
| ColorByTemperature of int
type Brightness = Brightness of int
type Light =
{ FriendlyName: string
Room: Room
Bulb: Bulb }

View file

@ -20,3 +20,34 @@ type ParseZigbeeEventError =
| UnknownType | UnknownType
type ParseEventError = ParseZigbeeEventError of ParseZigbeeEventError type ParseEventError = ParseZigbeeEventError of ParseZigbeeEventError
type Room =
| Bathroom
| LivingRoom
| Bedroom
type Bulb =
| IkeaBulb
| PaulmannBulb
type Light =
{ FriendlyName: string
Room: Room
Bulb: Bulb }
let lights =
[ { FriendlyName = "Vardagsrum - Fönsterlampa"
Room = LivingRoom
Bulb = IkeaBulb }
{ FriendlyName = "Vardagsrum - Vägglampa"
Room = LivingRoom
Bulb = PaulmannBulb }
{ FriendlyName = "Vardagsrum - Golvlampa"
Room = LivingRoom
Bulb = PaulmannBulb }
{ FriendlyName = "Badrum - Taklampa"
Room = Bathroom
Bulb = IkeaBulb }
{ FriendlyName = "Sovrum - Nattduksbordlampa"
Room = Bedroom
Bulb = IkeaBulb } ]

View file

@ -1,20 +1,35 @@
module internal NightLight.Core.Moods module internal NightLight.Core.Moods
open NightLight.Core.PartsOfDay open NightLight.Core.PartsOfDay
open NightLight.Core.Models
type Mood = type Mood =
| White | White
| Yellow | Yellow
| Red | Red
type Room =
| Bathroom
| LivingRoom
| Bedroom
let getDesiredMood room partOfDay = let getDesiredMood room partOfDay =
match room, partOfDay with match room, partOfDay with
| Bathroom, Day -> White | Bathroom, Day -> White
| LivingRoom, Day -> Yellow | LivingRoom, Day -> Yellow
| Bedroom, Day -> Yellow | Bedroom, Day -> Yellow
| _, Night -> Red | _, Night -> Red
type Color =
| ColorByCoordinates of float * float
| ColorByTemperature of int
type Brightness = Brightness of int
let getDesiredColorAndBrightness bulb mood =
let white = ColorByCoordinates(0.3227, 0.329)
let yellow = ColorByTemperature 454
let red = ColorByCoordinates(0.6942, 0.2963)
match bulb, mood with
| IkeaBulb, White -> white, Brightness 254
| IkeaBulb, Yellow -> yellow, Brightness 210
| IkeaBulb, Red -> red, Brightness 254
| PaulmannBulb, White -> white, Brightness 35
| PaulmannBulb, Yellow -> yellow, Brightness 35
| PaulmannBulb, Red -> red, Brightness 80

View file

@ -9,10 +9,8 @@
<Compile Include="Models.fs" /> <Compile Include="Models.fs" />
<Compile Include="PartsOfDay.fs" /> <Compile Include="PartsOfDay.fs" />
<Compile Include="Moods.fs" /> <Compile Include="Moods.fs" />
<Compile Include="Lights.fs" />
<Compile Include="ZigbeeEvents.fs" /> <Compile Include="ZigbeeEvents.fs" />
<Compile Include="ZigbeeCommands.fs" /> <Compile Include="ZigbeeCommands.fs" />
<Compile Include="Configuration.fs" />
<Compile Include="Core.fs" /> <Compile Include="Core.fs" />
</ItemGroup> </ItemGroup>

View file

@ -2,7 +2,7 @@ module internal NightLight.Core.ZigbeeCommands
open System.Text.Json.Nodes open System.Text.Json.Nodes
open NightLight.Core.Models open NightLight.Core.Models
open NightLight.Core.Lights open NightLight.Core.Moods
let generateZigbeeCommand friendlyName targetColor targetBrightness = let generateZigbeeCommand friendlyName targetColor targetBrightness =
let commandObj = JsonObject() let commandObj = JsonObject()