From c377ec25dccee044a39a6dff61cc9034f86ad6cf Mon Sep 17 00:00:00 2001 From: Sven van Heugten Date: Sat, 3 Jan 2026 19:24:37 +0100 Subject: [PATCH] Introduce the Models module in order to make others internal --- NightLight.Core/Core.fs | 10 +--------- NightLight.Core/Models.fs | 22 ++++++++++++++++++++++ NightLight.Core/NightLight.Core.fsproj | 1 + NightLight.Core/ZigbeeCommands.fs | 7 +++---- NightLight.Core/ZigbeeEvents.fs | 14 +++----------- NightLight/Program.fs | 3 +-- 6 files changed, 31 insertions(+), 26 deletions(-) create mode 100644 NightLight.Core/Models.fs diff --git a/NightLight.Core/Core.fs b/NightLight.Core/Core.fs index d6e972a..eb0c4f8 100644 --- a/NightLight.Core/Core.fs +++ b/NightLight.Core/Core.fs @@ -1,6 +1,6 @@ module NightLight.Core -open System +open NightLight.Models open NightLight.PartsOfDay open NightLight.ZigbeeEvents open NightLight.ZigbeeCommands @@ -18,14 +18,6 @@ let internal generateZigbeeCommandToFixLight partOfDay light = 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 = result { let partOfDay = getPartOfDay state.Time diff --git a/NightLight.Core/Models.fs b/NightLight.Core/Models.fs new file mode 100644 index 0000000..f4e6dc4 --- /dev/null +++ b/NightLight.Core/Models.fs @@ -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 diff --git a/NightLight.Core/NightLight.Core.fsproj b/NightLight.Core/NightLight.Core.fsproj index d8796ce..aea404b 100644 --- a/NightLight.Core/NightLight.Core.fsproj +++ b/NightLight.Core/NightLight.Core.fsproj @@ -6,6 +6,7 @@ + diff --git a/NightLight.Core/ZigbeeCommands.fs b/NightLight.Core/ZigbeeCommands.fs index 2ebbb08..f1572f1 100644 --- a/NightLight.Core/ZigbeeCommands.fs +++ b/NightLight.Core/ZigbeeCommands.fs @@ -1,11 +1,10 @@ -module NightLight.ZigbeeCommands +module internal NightLight.ZigbeeCommands open System.Text.Json.Nodes +open NightLight.Models open NightLight.Lights -type ZigbeeCommand = ZigbeeCommand of Topic: string * Payload: string - -let internal generateZigbeeCommand friendlyName targetColor targetBrightness = +let generateZigbeeCommand friendlyName targetColor targetBrightness = let commandObj = JsonObject() match targetColor with diff --git a/NightLight.Core/ZigbeeEvents.fs b/NightLight.Core/ZigbeeEvents.fs index 24f0b02..6dc6205 100644 --- a/NightLight.Core/ZigbeeEvents.fs +++ b/NightLight.Core/ZigbeeEvents.fs @@ -1,20 +1,12 @@ -module NightLight.ZigbeeEvents +module internal NightLight.ZigbeeEvents +open NightLight.Models open FsToolkit.ErrorHandling open FSharp.Data type ZigbeeEvent = DeviceAnnounce of FriendlyName: string -type ParseZigbeeEventError = - | InvalidJson - | MissingTypeField - | MissingDataField - | MissingFriendlyNameField - | InvalidTypeField - | InvalidFriendlyNameField - | UnknownType - -let internal parseZigbeeEvent str = +let parseZigbeeEvent str = result { let! jsonValue = JsonValue.TryParse str |> Result.requireSome InvalidJson diff --git a/NightLight/Program.fs b/NightLight/Program.fs index 16de5e0..7aa70ff 100644 --- a/NightLight/Program.fs +++ b/NightLight/Program.fs @@ -5,8 +5,7 @@ open System.Threading.Tasks open Microsoft.Extensions.Logging open MQTTnet open MQTTnet.Protocol -open NightLight.ZigbeeEvents -open NightLight.ZigbeeCommands +open NightLight.Models open NightLight.Core let private generateMqttMessage zigbeeCommand =