night-light/NightLight.Core/ZigbeeCommands.fs
2025-11-14 20:44:57 +01:00

26 lines
749 B
FSharp

module NightLight.ZigbeeCommands
open System.Text.Json.Nodes
open NightLight.Lights
type ZigbeeCommand = ZigbeeCommand of Topic: string * Payload: string
let internal generateZigbeeCommand friendlyName targetColor targetBrightness =
let commandObj = JsonObject()
match targetColor with
| ColorByCoordinates(x, y) ->
let colorObj = JsonObject()
colorObj["x"] <- x
colorObj["y"] <- y
commandObj["color"] <- colorObj
| ColorByTemperature t -> commandObj["color_temp"] <- t
commandObj["brightness"] <-
match targetBrightness with
| Brightness b -> b
let topic = $"zigbee2mqtt/{friendlyName}/set"
let payload = commandObj.ToJsonString()
ZigbeeCommand(topic, payload)