diff --git a/NightLight.Core/Core.fs b/NightLight.Core/Core.fs index eb0c4f8..4a5ed2f 100644 --- a/NightLight.Core/Core.fs +++ b/NightLight.Core/Core.fs @@ -18,7 +18,7 @@ let internal generateZigbeeCommandToFixLight partOfDay light = generateZigbeeCommand light.FriendlyName color brightness -let onEventReceived (state: State) (event: Event) : Result = +let onEventReceived (state: State) (event: Event) : Result = result { let partOfDay = getPartOfDay state.Time diff --git a/NightLight.Core/Models.fs b/NightLight.Core/Models.fs index 161902f..23bd86d 100644 --- a/NightLight.Core/Models.fs +++ b/NightLight.Core/Models.fs @@ -8,7 +8,7 @@ type Event = | ReceivedZigbeeEvent of payload: string | TimeChanged of DateTime -type Message = Message of Topic: string * Payload: string +type Message = { Topic: string; Payload: string } type ParseZigbeeEventError = | InvalidJson diff --git a/NightLight.Core/ZigbeeCommands.fs b/NightLight.Core/ZigbeeCommands.fs index 946b7c4..12cdb46 100644 --- a/NightLight.Core/ZigbeeCommands.fs +++ b/NightLight.Core/ZigbeeCommands.fs @@ -22,4 +22,4 @@ let generateZigbeeCommand friendlyName targetColor targetBrightness = let topic = $"zigbee2mqtt/{friendlyName}/set" let payload = commandObj.ToJsonString() - Message(topic, payload) + { Topic = topic; Payload = payload } diff --git a/NightLight/Program.fs b/NightLight/Program.fs index a1a4326..7daee6b 100644 --- a/NightLight/Program.fs +++ b/NightLight/Program.fs @@ -9,21 +9,17 @@ open NightLight.Models open NightLight.Core let private generateMqttMessage zigbeeCommand = - match zigbeeCommand with - | Message(topic, payload) -> - MqttApplicationMessageBuilder() - .WithTopic(topic) - .WithPayload(payload) - .WithQualityOfServiceLevel(MqttQualityOfServiceLevel.AtLeastOnce) - .Build() + MqttApplicationMessageBuilder() + .WithTopic(zigbeeCommand.Topic) + .WithPayload(zigbeeCommand.Payload) + .WithQualityOfServiceLevel(MqttQualityOfServiceLevel.AtLeastOnce) + .Build() -let private publishZigbeeCommands (mqttClient: IMqttClient) (logger: ILogger) (commands: ZigbeeCommand seq) = +let private publishZigbeeCommands (mqttClient: IMqttClient) (logger: ILogger) (commands: Message seq) = async { commands |> Seq.iter (fun command -> - match command with - | Message(topic, payload) -> - logger.LogInformation("Publishing message {Payload} to topic {Topic}...", payload, topic)) + logger.LogInformation("Publishing message {Payload} to topic {Topic}...", command.Payload, command.Topic)) return! commands