Put a full Message in ReceivedZigbeeEvent

We'll need the topic later.
This commit is contained in:
Sven van Heugten 2026-01-03 19:36:25 +01:00
parent 10e26a4866
commit 27c6646237
3 changed files with 9 additions and 7 deletions

View file

@ -4,12 +4,12 @@ open System
type State = { Time: DateTime }
type Event =
| ReceivedZigbeeEvent of payload: string
| TimeChanged of DateTime
type Message = { Topic: string; Payload: string }
type Event =
| ReceivedZigbeeEvent of Message
| TimeChanged of DateTime
type ParseZigbeeEventError =
| InvalidJson
| MissingTypeField

View file

@ -6,9 +6,9 @@ open FSharp.Data
type ZigbeeEvent = DeviceAnnounce of FriendlyName: string
let parseZigbeeEvent str =
let parseZigbeeEvent (message: Message) =
result {
let! jsonValue = JsonValue.TryParse str |> Result.requireSome InvalidJson
let! jsonValue = JsonValue.TryParse message.Payload |> Result.requireSome InvalidJson
let! messageType = jsonValue.TryGetProperty "type" |> Result.requireSome MissingTypeField
let! messageData = jsonValue.TryGetProperty "data" |> Result.requireSome MissingDataField