Demonstrate and fix some odd behaviour with some bulbs
This commit is contained in:
parent
10d858817d
commit
c1d9029a73
2 changed files with 12 additions and 6 deletions
|
|
@ -46,6 +46,9 @@ type FakeLight(light: Light) =
|
||||||
if hasPower then
|
if hasPower then
|
||||||
brightness <- newBrightness
|
brightness <- newBrightness
|
||||||
|
|
||||||
|
if light.Bulb = IkeaBulb then
|
||||||
|
state <- true
|
||||||
|
|
||||||
member _.SetColor(newColor: Color) =
|
member _.SetColor(newColor: Color) =
|
||||||
if hasPower then
|
if hasPower then
|
||||||
color <- newColor
|
color <- newColor
|
||||||
|
|
|
||||||
|
|
@ -12,12 +12,14 @@ 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 =
|
||||||
|
seq {
|
||||||
|
yield generateStateCommand state light
|
||||||
|
|
||||||
|
if state = On then
|
||||||
let color, brightness =
|
let color, brightness =
|
||||||
getDesiredMood light.Room partOfDay |> getDesiredColorAndBrightness light.Bulb
|
getDesiredMood light.Room partOfDay |> getDesiredColorAndBrightness light.Bulb
|
||||||
|
|
||||||
seq {
|
yield generateZigbeeCommand color brightness light
|
||||||
generateStateCommand state light
|
|
||||||
generateZigbeeCommand color brightness light
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type NightLightStateMachine private (maybeTime: DateTime option, lightToState: Map<Light, State>) =
|
type NightLightStateMachine private (maybeTime: DateTime option, lightToState: Map<Light, State>) =
|
||||||
|
|
@ -53,7 +55,8 @@ type NightLightStateMachine private (maybeTime: DateTime option, lightToState: M
|
||||||
|> Seq.fold (fun acc key -> Map.add key desiredLightState acc) lightToState
|
|> Seq.fold (fun acc key -> Map.add key desiredLightState acc) lightToState
|
||||||
|
|
||||||
NightLightStateMachine(maybeTime, newLightToState),
|
NightLightStateMachine(maybeTime, newLightToState),
|
||||||
remoteControlledLights |> Seq.map (generateStateCommand desiredLightState)
|
remoteControlledLights
|
||||||
|
|> Seq.collect (fun light -> generateZigbeeCommandsToFixLight desiredLightState partOfDay light)
|
||||||
| TimeChanged newTime, maybePartOfDay ->
|
| TimeChanged newTime, maybePartOfDay ->
|
||||||
let newState = NightLightStateMachine(Some newTime, lightToState)
|
let newState = NightLightStateMachine(Some newTime, lightToState)
|
||||||
let newPartOfDay = getPartOfDay newTime
|
let newPartOfDay = getPartOfDay newTime
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue