Transform onZigbeeEventReceived to onEventReceived
We'll add different events later.
This commit is contained in:
parent
f2864ffc47
commit
118dc03fdc
2 changed files with 15 additions and 10 deletions
|
|
@ -17,18 +17,22 @@ let internal generateZigbeeCommandToFixLight partOfDay light =
|
||||||
|
|
||||||
generateZigbeeCommand light.FriendlyName color brightness
|
generateZigbeeCommand light.FriendlyName color brightness
|
||||||
|
|
||||||
let onZigbeeEventReceived (partOfDay: PartOfDay) (decodedPayload: string) =
|
type Event = ReceivedZigbeeEvent of payload: string
|
||||||
|
|
||||||
|
let onEventReceived (partOfDay: PartOfDay) (event: Event) =
|
||||||
result {
|
result {
|
||||||
let! zigbeeEvent = parseZigbeeEvent decodedPayload
|
match event with
|
||||||
|
| ReceivedZigbeeEvent payload ->
|
||||||
|
let! zigbeeEvent = parseZigbeeEvent payload
|
||||||
|
|
||||||
return
|
return
|
||||||
match zigbeeEvent with
|
match zigbeeEvent with
|
||||||
| DeviceAnnounce friendlyName ->
|
| DeviceAnnounce friendlyName ->
|
||||||
let maybeLight = tryFindLight friendlyName
|
let maybeLight = tryFindLight friendlyName
|
||||||
|
|
||||||
match maybeLight with
|
match maybeLight with
|
||||||
| Some light -> generateZigbeeCommandToFixLight partOfDay light |> Seq.singleton
|
| Some light -> generateZigbeeCommandToFixLight partOfDay light |> Seq.singleton
|
||||||
| None -> Seq.empty
|
| None -> Seq.empty
|
||||||
}
|
}
|
||||||
|
|
||||||
let onPartOfDayChanged (partOfDay: PartOfDay) =
|
let onPartOfDayChanged (partOfDay: PartOfDay) =
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,8 @@ let private onMqttMessageReceived (mqttClient: IMqttClient) (logger: ILogger) (m
|
||||||
logger.LogInformation("Received message with payload {Payload}", decodedPayload)
|
logger.LogInformation("Received message with payload {Payload}", decodedPayload)
|
||||||
|
|
||||||
let commandsResult =
|
let commandsResult =
|
||||||
decodedPayload |> onZigbeeEventReceived (getPartOfDay DateTime.Now)
|
ReceivedZigbeeEvent decodedPayload
|
||||||
|
|> onEventReceived (getPartOfDay DateTime.Now)
|
||||||
|
|
||||||
match commandsResult with
|
match commandsResult with
|
||||||
| Ok commands -> publishZigbeeCommands mqttClient logger commands
|
| Ok commands -> publishZigbeeCommands mqttClient logger commands
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue