Introduce the Models module in order to make others internal

This commit is contained in:
Sven van Heugten 2026-01-03 19:24:37 +01:00
parent 915d01e086
commit c377ec25dc
6 changed files with 31 additions and 26 deletions

View file

@ -1,6 +1,6 @@
module NightLight.Core module NightLight.Core
open System open NightLight.Models
open NightLight.PartsOfDay open NightLight.PartsOfDay
open NightLight.ZigbeeEvents open NightLight.ZigbeeEvents
open NightLight.ZigbeeCommands open NightLight.ZigbeeCommands
@ -18,14 +18,6 @@ let internal generateZigbeeCommandToFixLight partOfDay light =
generateZigbeeCommand light.FriendlyName color brightness generateZigbeeCommand light.FriendlyName color brightness
type Event =
| ReceivedZigbeeEvent of payload: string
| TimeChanged of DateTime
type ParseEventError = ParseZigbeeEventError of ParseZigbeeEventError
type State = { Time: DateTime }
let onEventReceived (state: State) (event: Event) : Result<State * ZigbeeCommand seq, ParseEventError> = let onEventReceived (state: State) (event: Event) : Result<State * ZigbeeCommand seq, ParseEventError> =
result { result {
let partOfDay = getPartOfDay state.Time let partOfDay = getPartOfDay state.Time

22
NightLight.Core/Models.fs Normal file
View file

@ -0,0 +1,22 @@
module NightLight.Models
open System
type State = { Time: DateTime }
type Event =
| ReceivedZigbeeEvent of payload: string
| TimeChanged of DateTime
type ZigbeeCommand = ZigbeeCommand of Topic: string * Payload: string
type ParseZigbeeEventError =
| InvalidJson
| MissingTypeField
| MissingDataField
| MissingFriendlyNameField
| InvalidTypeField
| InvalidFriendlyNameField
| UnknownType
type ParseEventError = ParseZigbeeEventError of ParseZigbeeEventError

View file

@ -6,6 +6,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<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="Lights.fs" />

View file

@ -1,11 +1,10 @@
module NightLight.ZigbeeCommands module internal NightLight.ZigbeeCommands
open System.Text.Json.Nodes open System.Text.Json.Nodes
open NightLight.Models
open NightLight.Lights open NightLight.Lights
type ZigbeeCommand = ZigbeeCommand of Topic: string * Payload: string let generateZigbeeCommand friendlyName targetColor targetBrightness =
let internal generateZigbeeCommand friendlyName targetColor targetBrightness =
let commandObj = JsonObject() let commandObj = JsonObject()
match targetColor with match targetColor with

View file

@ -1,20 +1,12 @@
module NightLight.ZigbeeEvents module internal NightLight.ZigbeeEvents
open NightLight.Models
open FsToolkit.ErrorHandling open FsToolkit.ErrorHandling
open FSharp.Data open FSharp.Data
type ZigbeeEvent = DeviceAnnounce of FriendlyName: string type ZigbeeEvent = DeviceAnnounce of FriendlyName: string
type ParseZigbeeEventError = let parseZigbeeEvent str =
| InvalidJson
| MissingTypeField
| MissingDataField
| MissingFriendlyNameField
| InvalidTypeField
| InvalidFriendlyNameField
| UnknownType
let internal parseZigbeeEvent str =
result { result {
let! jsonValue = JsonValue.TryParse str |> Result.requireSome InvalidJson let! jsonValue = JsonValue.TryParse str |> Result.requireSome InvalidJson

View file

@ -5,8 +5,7 @@ open System.Threading.Tasks
open Microsoft.Extensions.Logging open Microsoft.Extensions.Logging
open MQTTnet open MQTTnet
open MQTTnet.Protocol open MQTTnet.Protocol
open NightLight.ZigbeeEvents open NightLight.Models
open NightLight.ZigbeeCommands
open NightLight.Core open NightLight.Core
let private generateMqttMessage zigbeeCommand = let private generateMqttMessage zigbeeCommand =