Put a full Message in ReceivedZigbeeEvent
We'll need the topic later.
This commit is contained in:
parent
10e26a4866
commit
27c6646237
3 changed files with 9 additions and 7 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue