Turn Message into a record type
This commit is contained in:
parent
ab6e123efc
commit
10e26a4866
4 changed files with 10 additions and 14 deletions
|
|
@ -18,7 +18,7 @@ let internal generateZigbeeCommandToFixLight partOfDay light =
|
||||||
|
|
||||||
generateZigbeeCommand light.FriendlyName color brightness
|
generateZigbeeCommand light.FriendlyName color brightness
|
||||||
|
|
||||||
let onEventReceived (state: State) (event: Event) : Result<State * ZigbeeCommand seq, ParseEventError> =
|
let onEventReceived (state: State) (event: Event) : Result<State * Message seq, ParseEventError> =
|
||||||
result {
|
result {
|
||||||
let partOfDay = getPartOfDay state.Time
|
let partOfDay = getPartOfDay state.Time
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ type Event =
|
||||||
| ReceivedZigbeeEvent of payload: string
|
| ReceivedZigbeeEvent of payload: string
|
||||||
| TimeChanged of DateTime
|
| TimeChanged of DateTime
|
||||||
|
|
||||||
type Message = Message of Topic: string * Payload: string
|
type Message = { Topic: string; Payload: string }
|
||||||
|
|
||||||
type ParseZigbeeEventError =
|
type ParseZigbeeEventError =
|
||||||
| InvalidJson
|
| InvalidJson
|
||||||
|
|
|
||||||
|
|
@ -22,4 +22,4 @@ let generateZigbeeCommand friendlyName targetColor targetBrightness =
|
||||||
let topic = $"zigbee2mqtt/{friendlyName}/set"
|
let topic = $"zigbee2mqtt/{friendlyName}/set"
|
||||||
let payload = commandObj.ToJsonString()
|
let payload = commandObj.ToJsonString()
|
||||||
|
|
||||||
Message(topic, payload)
|
{ Topic = topic; Payload = payload }
|
||||||
|
|
|
||||||
|
|
@ -9,21 +9,17 @@ open NightLight.Models
|
||||||
open NightLight.Core
|
open NightLight.Core
|
||||||
|
|
||||||
let private generateMqttMessage zigbeeCommand =
|
let private generateMqttMessage zigbeeCommand =
|
||||||
match zigbeeCommand with
|
|
||||||
| Message(topic, payload) ->
|
|
||||||
MqttApplicationMessageBuilder()
|
MqttApplicationMessageBuilder()
|
||||||
.WithTopic(topic)
|
.WithTopic(zigbeeCommand.Topic)
|
||||||
.WithPayload(payload)
|
.WithPayload(zigbeeCommand.Payload)
|
||||||
.WithQualityOfServiceLevel(MqttQualityOfServiceLevel.AtLeastOnce)
|
.WithQualityOfServiceLevel(MqttQualityOfServiceLevel.AtLeastOnce)
|
||||||
.Build()
|
.Build()
|
||||||
|
|
||||||
let private publishZigbeeCommands (mqttClient: IMqttClient) (logger: ILogger) (commands: ZigbeeCommand seq) =
|
let private publishZigbeeCommands (mqttClient: IMqttClient) (logger: ILogger) (commands: Message seq) =
|
||||||
async {
|
async {
|
||||||
commands
|
commands
|
||||||
|> Seq.iter (fun command ->
|
|> Seq.iter (fun command ->
|
||||||
match command with
|
logger.LogInformation("Publishing message {Payload} to topic {Topic}...", command.Payload, command.Topic))
|
||||||
| Message(topic, payload) ->
|
|
||||||
logger.LogInformation("Publishing message {Payload} to topic {Topic}...", payload, topic))
|
|
||||||
|
|
||||||
return!
|
return!
|
||||||
commands
|
commands
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue