Spam a bit less

This commit is contained in:
Sven van Heugten 2026-01-10 21:04:20 +01:00
parent c5088ae218
commit 2f6e46960f
2 changed files with 15 additions and 6 deletions

View file

@ -11,15 +11,19 @@ open FsToolkit.ErrorHandling
let internal tryFindLight friendlyName = let internal tryFindLight friendlyName =
Seq.tryFind (fun light -> light.FriendlyName = friendlyName) lights Seq.tryFind (fun light -> light.FriendlyName = friendlyName) lights
let internal generateZigbeeCommandsToFixLight state partOfDay light = let internal generateZigbeeCommandsToFixLight state partOfDay (light: Light) =
seq { seq {
yield generateStateCommand state light match light.ControlledWithRemote, state with
| true, _ -> yield generateStateCommand state light
| false, On -> ()
| false, Off -> failwith $"Unexpectly trying to turn off {light}. It's not remote-controlled."
if state = On then if state = On then
let color, brightness = let color, brightness =
getDesiredMood light.Room partOfDay |> getDesiredColorAndBrightness light.Bulb getDesiredMood light.Room partOfDay |> getDesiredColorAndBrightness light.Bulb
yield generateZigbeeCommand color brightness light yield generateColorCommand light color
yield generateBrightnessCommand light brightness
} }
type NightLightStateMachine private (maybeTime: DateTime option, lightToState: Map<Light, State>) = type NightLightStateMachine private (maybeTime: DateTime option, lightToState: Map<Light, State>) =

View file

@ -25,10 +25,10 @@ let generateStateCommand state light =
commandObj.ToJsonString() |> toZigbeeCommand light commandObj.ToJsonString() |> toZigbeeCommand light
let generateZigbeeCommand targetColor targetBrightness light = let internal generateColorCommand light color =
let commandObj = JsonObject() let commandObj = JsonObject()
match targetColor with match color with
| ColorByCoordinates(x, y) -> | ColorByCoordinates(x, y) ->
let colorObj = JsonObject() let colorObj = JsonObject()
colorObj["x"] <- x colorObj["x"] <- x
@ -36,8 +36,13 @@ let generateZigbeeCommand targetColor targetBrightness light =
commandObj["color"] <- colorObj commandObj["color"] <- colorObj
| ColorByTemperature t -> commandObj["color_temp"] <- t | ColorByTemperature t -> commandObj["color_temp"] <- t
commandObj.ToJsonString() |> toZigbeeCommand light
let internal generateBrightnessCommand light brightness =
let commandObj = JsonObject()
commandObj["brightness"] <- commandObj["brightness"] <-
match targetBrightness with match brightness with
| Brightness b -> b | Brightness b -> b
commandObj.ToJsonString() |> toZigbeeCommand light commandObj.ToJsonString() |> toZigbeeCommand light