diff --git a/NightLight.Core.Tests/FakeHome.fs b/NightLight.Core.Tests/FakeHome.fs index df2da1b..f9b9d2d 100644 --- a/NightLight.Core.Tests/FakeHome.fs +++ b/NightLight.Core.Tests/FakeHome.fs @@ -59,23 +59,20 @@ type FakeHome(now: DateTime) = member _.LightStates = friendlyNameToFakeLight.Values |> Seq.map _.LightWithState - member _.Interact(interaction: Interaction) : Result = - result { - match interaction with - | HumanInteraction(LightTurnedOn light) -> - friendlyNameToFakeLight[light.FriendlyName].TurnOn() + member _.Interact(interaction: Interaction) = + match interaction with + | HumanInteraction(LightTurnedOn light) -> + friendlyNameToFakeLight[light.FriendlyName].TurnOn() - do! - { Topic = "zigbee2mqtt/bridge/event" - Payload = - $@"{{ - ""type"": ""device_announce"", - ""data"": {{ ""friendly_name"": ""{light.FriendlyName}"" }} - }}" } - |> nightLightStateMachine.SendMessage - | HumanInteraction(LightTurnedOff light) -> friendlyNameToFakeLight[light.FriendlyName].TurnOff() - | TimeChanged time -> do! nightLightStateMachine.ChangeTime time + { Topic = "zigbee2mqtt/bridge/event" + Payload = + $@"{{ + ""type"": ""device_announce"", + ""data"": {{ ""friendly_name"": ""{light.FriendlyName}"" }} + }}" } + |> nightLightStateMachine.SendMessage + | HumanInteraction(LightTurnedOff light) -> friendlyNameToFakeLight[light.FriendlyName].TurnOff() + | TimeChanged time -> nightLightStateMachine.ChangeTime time - nightLightStateMachine.TransmittedCommands |> Seq.iter processCommand - nightLightStateMachine.ClearTransmittedCommands() - } + nightLightStateMachine.TransmittedCommands |> Seq.iter processCommand + nightLightStateMachine.ClearTransmittedCommands() diff --git a/NightLight.Core.Tests/NightLightStateMachine.fs b/NightLight.Core.Tests/NightLightStateMachine.fs index 0379a3b..f552cb1 100644 --- a/NightLight.Core.Tests/NightLightStateMachine.fs +++ b/NightLight.Core.Tests/NightLightStateMachine.fs @@ -11,12 +11,18 @@ type NightLightStateMachine(now: DateTime) = let transmittedCommands = new List() + let assertIsOk (result: Result) : unit = + match result with + | Ok() -> () + | Error error -> failwith $"Expected Ok, got Error {error}" + let sendEvent event = result { let! newState, commands = onEventReceived state event state <- newState transmittedCommands.AddRange commands } + |> assertIsOk member _.TransmittedCommands = transmittedCommands.AsReadOnly() diff --git a/NightLight.Core.Tests/NightLightTests.fs b/NightLight.Core.Tests/NightLightTests.fs index b7419fd..0fe7190 100644 --- a/NightLight.Core.Tests/NightLightTests.fs +++ b/NightLight.Core.Tests/NightLightTests.fs @@ -2,15 +2,9 @@ module NightLight.Core.Tests.NightLightTests open FsCheck.Xunit -let private assertIsOk (result: Result) : unit = - match result with - | Ok() -> () - | Error error -> failwith $"Expected Ok, got Error {error}" - [ |])>] let ``Brightness should always be under 255`` (fakeHome: FakeHome) (interactions: Interaction list) = - interactions - |> Seq.iter (fun interaction -> fakeHome.Interact interaction |> assertIsOk) + interactions |> Seq.iter (fun interaction -> fakeHome.Interact interaction) fakeHome.LightStates |> Seq.choose (fun (_, state) ->