Strongly type the device FriendlyName

This commit is contained in:
Sven van Heugten 2026-01-05 17:51:57 +01:00
parent 8cc59c4738
commit 89a8c599c7
4 changed files with 23 additions and 12 deletions

View file

@ -4,7 +4,7 @@ open NightLight.Core.Models
open FsToolkit.ErrorHandling
open FSharp.Data
type ZigbeeEvent = DeviceAnnounce of FriendlyName: string
type ZigbeeEvent = DeviceAnnounce of DeviceFriendlyName
let parseZigbeeEvent (message: Message) =
result {
@ -17,7 +17,7 @@ let parseZigbeeEvent (message: Message) =
match messageType with
| JsonValue.String "device_announce" ->
match messageData.TryGetProperty "friendly_name" with
| Some(JsonValue.String friendlyName) -> Ok(DeviceAnnounce friendlyName)
| Some(JsonValue.String friendlyName) -> Ok <| DeviceAnnounce(DeviceFriendlyName friendlyName)
| Some _ -> Error InvalidFriendlyNameField
| None -> Error MissingFriendlyNameField
| JsonValue.String _ -> Error UnknownType