Hard code the lights controlled by the remote

This commit is contained in:
Sven van Heugten 2026-02-27 17:59:25 +01:00
parent 50c8a413a6
commit 3855439d82
5 changed files with 40 additions and 37 deletions

View file

@ -13,11 +13,17 @@ let internal tryFindLight friendlyName =
let internal generateZigbeeCommandsToFixLight (light: Light) (desiredLightState: LightState) =
seq {
match (lightProps light).ControlledWithRemote, desiredLightState.State with
| NonRemote, On -> ()
| NonRemote, Off -> failwith $"Unexpectly trying to turn off {light}. It's not remote-controlled."
| _, On when (lightProps light).Bulb = IkeaBulb -> () // Rely on the brightness command for turning it on
| _, _ -> yield generateStateCommand desiredLightState.State light
let isRemoteControlled =
light = VardagsrumFonsterlampa || light = SovrumNattduksbordlampa
if not isRemoteControlled then
match desiredLightState.State with
| On -> ()
| Off -> failwith $"Unexpectly trying to turn off {light}. It's not remote-controlled."
else if desiredLightState.State = On && (lightProps light).Bulb = IkeaBulb then
() // Rely on the brightness command for turning it on
else
yield generateStateCommand desiredLightState.State light
if desiredLightState.State = On then
yield generateBrightnessCommand light desiredLightState.Brightness
@ -51,7 +57,7 @@ let internal createOrUpdateNightLightState
light,
{ Color = color
Brightness =
if alarm && (lightProps light).ControlledWithRemote <> NonRemote then
if alarm && (light = VardagsrumFonsterlampa || light = SovrumNattduksbordlampa) then
brightness.Scale(getAlarmWeight time)
else
brightness
@ -73,7 +79,7 @@ let internal withStateFor (light: Light) (state: State) (oldNightLightState: Nig
let internal withStateForRemoteControlledLights (state: State) (oldNightLightState: NightLightState) =
lights
|> Seq.filter (fun light -> (lightProps light).ControlledWithRemote.IsNonRemote |> not)
|> Seq.filter (fun light -> light = VardagsrumFonsterlampa || light = SovrumNattduksbordlampa)
|> Seq.fold (fun acc light -> acc |> withStateFor light state) oldNightLightState
let internal withAlarmOff (oldNightLightState: NightLightState) =
@ -114,8 +120,7 @@ type NightLightStateMachine private (maybeState: NightLightState option) =
| PressedOff -> currentState |> withAlarmOff |> withStateForRemoteControlledLights Off
| PressedLeft ->
let lightThatShouldBeOn =
lights
|> Seq.find (fun light -> (lightProps light).ControlledWithRemote = RemoteLeft)
lights |> Seq.find (fun light -> light = SovrumNattduksbordlampa)
currentState
|> withAlarmOff