diff --git a/NightLight.Core.Tests/FakeHome.fs b/NightLight.Core.Tests/FakeHome.fs index 65bfc62..6642cc3 100644 --- a/NightLight.Core.Tests/FakeHome.fs +++ b/NightLight.Core.Tests/FakeHome.fs @@ -6,11 +6,12 @@ open NightLight.Core.Models open FsToolkit.ErrorHandling open FSharp.Data -type RemoteInteraction = +type BedroomControllingRemoteInteraction = | RemotePressedOnButton | RemotePressedOffButton | RemotePressedLeftButton - | RemotePressedRightButton + +type LivingRoomControllingRemoteAction = | RemotePressedRightButton type HumanInteraction = | LightPoweredOn of Light @@ -18,7 +19,8 @@ type HumanInteraction = type Interaction = | HumanInteraction of HumanInteraction - | RemoteInteraction of RemoteInteraction + | BedroomControllingRemoteInteraction of BedroomControllingRemoteInteraction + | LivingRoomControllingRemoteInteraction of LivingRoomControllingRemoteAction | TimeChanged of DateTime type Color = @@ -123,22 +125,22 @@ type FakeHome() = |> ReceivedZigbeeEvent |> onEventPublished.Trigger | HumanInteraction(LightPoweredOff light) -> friendlyNameToFakeLight[(lightProps light).FriendlyName].PowerOff() - | RemoteInteraction RemotePressedOnButton -> + | BedroomControllingRemoteInteraction RemotePressedOnButton -> { Topic = $"zigbee2mqtt/{remoteControlFriendlyName.Get}" Payload = @"{ ""action"": ""on"" }" } |> ReceivedZigbeeEvent |> onEventPublished.Trigger - | RemoteInteraction RemotePressedOffButton -> + | BedroomControllingRemoteInteraction RemotePressedOffButton -> { Topic = $"zigbee2mqtt/{remoteControlFriendlyName.Get}" Payload = @"{ ""action"": ""off"" }" } |> ReceivedZigbeeEvent |> onEventPublished.Trigger - | RemoteInteraction RemotePressedLeftButton -> + | BedroomControllingRemoteInteraction RemotePressedLeftButton -> { Topic = $"zigbee2mqtt/{remoteControlFriendlyName.Get}" Payload = @"{ ""action"": ""arrow_left_click"" }" } |> ReceivedZigbeeEvent |> onEventPublished.Trigger - | RemoteInteraction RemotePressedRightButton -> + | LivingRoomControllingRemoteInteraction RemotePressedRightButton -> { Topic = $"zigbee2mqtt/{remoteControlFriendlyName.Get}" Payload = @"{ ""action"": ""arrow_right_click"" }" } |> ReceivedZigbeeEvent diff --git a/NightLight.Core.Tests/InteractionListGenerators.fs b/NightLight.Core.Tests/InteractionListGenerators.fs index 7b7b484..a0b29df 100644 --- a/NightLight.Core.Tests/InteractionListGenerators.fs +++ b/NightLight.Core.Tests/InteractionListGenerators.fs @@ -36,12 +36,11 @@ let private genHumanInteraction = |> Gen.map Interaction.HumanInteraction let private genRemoteInteraction = - Gen.elements - [ RemotePressedOnButton - RemotePressedOffButton - RemotePressedLeftButton - RemotePressedRightButton ] - |> Gen.map RemoteInteraction + Gen.oneof + [ Gen.elements [ RemotePressedOnButton; RemotePressedOffButton; RemotePressedLeftButton ] + |> Gen.map BedroomControllingRemoteInteraction + + Gen.constant (LivingRoomControllingRemoteInteraction RemotePressedRightButton) ] let private genInteraction = Gen.frequency [ 4, genTimeChanged; 1, genHumanInteraction; 1, genRemoteInteraction ] diff --git a/NightLight.Core.Tests/InteractionListHelpers.fs b/NightLight.Core.Tests/InteractionListHelpers.fs index 8d7f8ae..958157d 100644 --- a/NightLight.Core.Tests/InteractionListHelpers.fs +++ b/NightLight.Core.Tests/InteractionListHelpers.fs @@ -36,17 +36,13 @@ let doesLightHavePowerAfterInteractions light interactions = |> Seq.tryLast |> Option.defaultValue false -let tryGetLastBedroomRemoteInteraction interactions = +let tryGetLastBedroomControllingRemoteInteraction interactions = interactions |> Seq.indexed |> Seq.choose (fun (index, interaction) -> match interaction with - | Interaction.RemoteInteraction remoteInteraction -> - match remoteInteraction with - | RemotePressedOnButton - | RemotePressedOffButton - | RemotePressedLeftButton -> Some(index, remoteInteraction) - | RemotePressedRightButton -> None + | Interaction.BedroomControllingRemoteInteraction bedroomRemoteInteraction -> + Some(index, bedroomRemoteInteraction) | _ -> None) |> Seq.tryLast diff --git a/NightLight.Core.Tests/NightLightTests.fs b/NightLight.Core.Tests/NightLightTests.fs index 14e89c5..96d2ec4 100644 --- a/NightLight.Core.Tests/NightLightTests.fs +++ b/NightLight.Core.Tests/NightLightTests.fs @@ -47,7 +47,7 @@ type NightLightTests() = let time = getTimeAfterInteractions interactions |> _.TimeOfDay let alarm = - hasNewDayStartedSince interactions (tryGetLastBedroomRemoteInteraction interactions) + hasNewDayStartedSince interactions (tryGetLastBedroomControllingRemoteInteraction interactions) && startOfDay <= time && time <= endOfAlarm @@ -90,15 +90,16 @@ type NightLightTests() = |> Seq.filter (fun (light, _) -> doesLightHavePowerAfterInteractions light interactions) |> Seq.toList - let lastBedroomRemoteInteraction = tryGetLastBedroomRemoteInteraction interactions + let lastBedroomControllingRemoteInteraction = + tryGetLastBedroomControllingRemoteInteraction interactions let newDayStartedSinceBedroomRemote = - hasNewDayStartedSince interactions lastBedroomRemoteInteraction + hasNewDayStartedSince interactions lastBedroomControllingRemoteInteraction let hasPressedRight = interactions |> Seq.exists (function - | Interaction.RemoteInteraction RemotePressedRightButton -> true + | Interaction.LivingRoomControllingRemoteInteraction RemotePressedRightButton -> true | _ -> false) let isExpectedOn light = @@ -108,11 +109,10 @@ type NightLightTests() = if newDayStartedSinceBedroomRemote then true else - match lastBedroomRemoteInteraction with + match lastBedroomControllingRemoteInteraction with | Some(_, RemotePressedOffButton) -> false | Some(_, RemotePressedLeftButton) -> light = LeftBedroomLamp | Some(_, RemotePressedOnButton) -> true - | Some(_, RemotePressedRightButton) -> failwith "unexpected" | None -> true | LivingRoomWallLamp | LivingRoomFloorLamp -> not hasPressedRight @@ -120,7 +120,8 @@ type NightLightTests() = lightsWithPower |> Seq.forall (fun (light, state) -> state.IsOn = isExpectedOn light) - |> Prop.collect $"last bedroom remote interaction is {lastBedroomRemoteInteraction |> Option.map snd}" + |> Prop.collect + $"last bedroom controlling remote interaction is {lastBedroomControllingRemoteInteraction |> Option.map snd}" |> Prop.collect $"pressed right: {hasPressedRight}" |> Prop.collect $"{lightsWithPower.Length} light(s) with power" |> Prop.classify newDayStartedSinceBedroomRemote "new day since bedroom remote"