Esempio n. 1
0
        public async Task TurnOnEntityCallsCorrectServiceCall()
        {
            // ARRANGE
            // ACT
            await DefaultDaemonHost
            .Entity("light.correct_entity")
            .TurnOn()
            .ExecuteAsync();

            // ASSERT
            DefaultHassClientMock.VerifyCallServiceTimes("turn_on", Times.Once());
            DefaultHassClientMock.VerifyCallService("light", "turn_on", ("entity_id", "light.correct_entity"));
        }
Esempio n. 2
0
        public async Task MediaPlayerPauseCallsCorrectServiceCall()
        {
            // ARRANGE
            // ACT
            await DefaultDaemonHost
            .MediaPlayer("media_player.player")
            .Pause()
            .ExecuteAsync();

            // ASSERT
            DefaultHassClientMock.VerifyCallServiceTimes("media_pause", Times.Once());
            DefaultHassClientMock.VerifyCallService("media_player", "media_pause", ("entity_id", "media_player.player"));
        }
Esempio n. 3
0
        public async Task InputSelectSetOptionIEnumerableShouldCallCorrectCallService()
        {
            // ARRANGE
            // ACT
            await DefaultDaemonApp
            .InputSelects(new string[] { "input_select.myselect" })
            .SetOption("option1")
            .ExecuteAsync();

            // ASSERT
            DefaultHassClientMock.VerifyCallServiceTimes("select_option", Times.Once());
            DefaultHassClientMock.VerifyCallService("input_select", "select_option",
                                                    ("entity_id", "input_select.myselect"),
                                                    ("option", "option1"));
        }
Esempio n. 4
0
        public async Task TimerToggleShouldCallCorrectServiceCall()
        {
            // ARRANGE
            DefaultDaemonHost
            .Timer()
            .Every(TimeSpan.FromMilliseconds(20))
            .Entity("light.correct_light")
            .Toggle()
            .Execute();

            await RunDefauldDaemonUntilCanceled();

            // ASSERT
            DefaultHassClientMock.VerifyCallServiceTimes("toggle", Times.AtLeast(2)); // Less cause of slow cloud CI builds
            DefaultHassClientMock.VerifyCallService("light", "toggle", ("entity_id", "light.correct_light"));
        }
Esempio n. 5
0
        public async Task CameraEnableMotionDetectionCallsCorrectServiceCall()
        {
            // ARRANGE
            var entityId     = "camera.camera1";
            var service_call = "enable_motion_detection";

            // ACT
            await DefaultDaemonApp
            .Camera(entityId)
            .EnableMotionDetection()
            .ExecuteAsync();

            // ASSERT
            DefaultHassClientMock.VerifyCallServiceTimes(service_call, Times.Once());
            DefaultHassClientMock.VerifyCallService("camera", service_call, ("entity_id", entityId));
        }
Esempio n. 6
0
        public async Task CameraTurnOffCallsCorrectServiceCall()
        {
            // ARRANGE
            var entityId     = "camera.camera1";
            var service_call = "turn_off";

            // ACT
            await DefaultDaemonApp
            .Camera(entityId)
            .TurnOff()
            .ExecuteAsync();

            // ASSERT
            DefaultHassClientMock.VerifyCallServiceTimes(service_call, Times.Once());
            DefaultHassClientMock.VerifyCallService("camera", service_call, ("entity_id", entityId));
        }
Esempio n. 7
0
        public async Task TimerTurnOffShouldCallCorrectServiceCall()
        {
            // ARRANGE
            DefaultDaemonHost
            .Timer()
            .Every(TimeSpan.FromMilliseconds(20))
            .Entity("light.correct_light")
            .TurnOff()
            .Execute();

            await RunDefauldDaemonUntilCanceled(200);

            // ASSERT
            DefaultHassClientMock.VerifyCallServiceTimes("turn_off", Times.AtLeast(2));
            DefaultHassClientMock.VerifyCallService("light", "turn_off", ("entity_id", "light.correct_light"));
        }
Esempio n. 8
0
        public async Task TurnOffMultipleEntityCallsCorrectServiceCall()
        {
            // ARRANGE

            // ACT
            await DefaultDaemonApp
            .Entity("light.correct_entity", "light.correct_entity2")
            .TurnOff()
            .ExecuteAsync();

            // ASSERT
            DefaultHassClientMock.VerifyCallServiceTimes("turn_off", Times.Exactly(2));

            DefaultHassClientMock.VerifyCallService("light", "turn_off", ("entity_id", "light.correct_entity"));
            DefaultHassClientMock.VerifyCallService("light", "turn_off", ("entity_id", "light.correct_entity2"));
        }
Esempio n. 9
0
        public async Task TimerEveryWithAttributeShouldCallServiceCorrectNumberOfTimes()
        {
            // ARRANGE
            DefaultDaemonHost
            .Timer()
            .Every(TimeSpan.FromMilliseconds(20))
            .Entity("light.correct_light")
            .TurnOn()
            .UsingAttribute("attr", "on")
            .Execute();

            await RunDefauldDaemonUntilCanceled();

            // ASSERT
            DefaultHassClientMock.VerifyCallServiceTimes("turn_on", Times.AtLeast(4));
            DefaultHassClientMock.VerifyCallService("light", "turn_on", ("attr", "on"), ("entity_id", "light.correct_light"));
        }
Esempio n. 10
0
        public async Task TurnOffEntityLamdaSelectionCallsCorrectServiceCall()
        {
            // ARRANGE
            await RunDefauldDaemonUntilCanceled();

            // ACT
            await DefaultDaemonApp
            .Entities(n => n.EntityId.StartsWith("light.correct_entity"))
            .TurnOff()
            .ExecuteAsync();

            // ASSERT

            DefaultHassClientMock.VerifyCallServiceTimes("turn_off", Times.Exactly(2));
            DefaultHassClientMock.VerifyCallService("light", "turn_off", ("entity_id", "light.correct_entity"));
            DefaultHassClientMock.VerifyCallService("light", "turn_off", ("entity_id", "light.correct_entity2"));
        }
Esempio n. 11
0
        public async Task TurnOffLightLambdaAttributeSelectionCallsCorrectServiceCall()
        {
            // ARRANGE
            var cancelSource = DefaultHassClientMock.GetSourceWithTimeout();
            await DefaultDaemonHost.Run("host", 8123, false, "token", cancelSource.Token);

            // ACT
            await DefaultDaemonHost
            .Lights(n => n?.Attribute?.test >= 100)
            .TurnOff()
            .ExecuteAsync();

            // ASSERT
            DefaultHassClientMock.VerifyCallServiceTimes("turn_off", Times.Exactly(2));
            DefaultHassClientMock.VerifyCallService("light", "turn_off", ("entity_id", "light.correct_entity"));
            DefaultHassClientMock.VerifyCallService("light", "turn_off", ("entity_id", "light.correct_entity2"));
        }
Esempio n. 12
0
        public async Task InputSelectSetOptionFuncShouldCallCorrectCallService()
        {
            // ARRANGE
            DefaultDaemonHost.InternalState["input_select.myselect"] = new EntityState {
                EntityId = "input_select.myselect"
            };
            // ACT
            await DefaultDaemonApp
            .InputSelects(n => n.EntityId == "input_select.myselect")
            .SetOption("option1")
            .ExecuteAsync();

            // ASSERT
            DefaultHassClientMock.VerifyCallServiceTimes("select_option", Times.Once());
            DefaultHassClientMock.VerifyCallService("input_select", "select_option",
                                                    ("entity_id", "input_select.myselect"),
                                                    ("option", "option1"));
        }
Esempio n. 13
0
        public async Task TurnOnEntityWithMultipleAttributeCallsCorrectServiceCall()
        {
            // ARRANGE
            // ACT
            await DefaultDaemonApp
            .Entity("light.correct_entity")
            .TurnOn()
            .WithAttribute("brightness", 100)
            .WithAttribute("color_temp", 230)
            .ExecuteAsync();

            // ASSERT
            DefaultHassClientMock.VerifyCallServiceTimes("turn_on", Times.Once());
            DefaultHassClientMock.VerifyCallService("light", "turn_on",
                                                    ("brightness", 100),
                                                    ("color_temp", 230),
                                                    ("entity_id", "light.correct_entity"));
        }
Esempio n. 14
0
        public async Task TimerEntitiesEveryShouldCallServiceCorrectNumberOfTimes()
        {
            // ARRANGE
            DefaultDaemonHost
            .Timer()
            .Every(TimeSpan.FromMilliseconds(20))
            .Entities(new string[] { "light.correct_light" })
            .TurnOn()
            .Execute();

            var cancelSource = new CancellationTokenSource(100); //DefaultHassClientMock.GetSourceWithTimeout(100);

            // ACTION
            await RunDefauldDaemonUntilCanceled();

            // ASSERT
            DefaultHassClientMock.VerifyCallServiceTimes("turn_on", Times.AtLeast(4));
            DefaultHassClientMock.VerifyCallService("light", "turn_on", ("entity_id", "light.correct_light"));
        }
Esempio n. 15
0
        public async Task EntityOnStateChangedEntitiesTurnOnLightCallsCorrectServiceCall()
        {
            // ARRANGE
            DefaultHassClientMock.AddChangedEvent("binary_sensor.pir", "off", "on");

            var cancelSource = DefaultHassClientMock.GetSourceWithTimeout();

            DefaultDaemonApp
            .Entity("binary_sensor.pir")
            .WhenStateChange("on")
            .UseEntities(new string[] { "light.correct_entity" })
            .TurnOn()
            .Execute();

            await RunDefauldDaemonUntilCanceled();

            DefaultHassClientMock.VerifyCallServiceTimes("turn_on", Times.Once());
            DefaultHassClientMock.VerifyCallService("light", "turn_on", ("entity_id", "light.correct_entity"));
        }
Esempio n. 16
0
        public async Task OneEntityWithSeveralShouldCallsCorrectServiceCall()
        {
            // ARRANGE
            DefaultHassClientMock.AddChangedEvent("binary_sensor.pir", "off", "on");

            var cancelSource = DefaultHassClientMock.GetSourceWithTimeout();

            DefaultDaemonApp
            .Entity("binary_sensor.pir")
            .WhenStateChange((n, _) => n?.State == "on")
            .UseEntity("light.correct_entity")
            .Toggle()
            .Execute();

            await RunDefauldDaemonUntilCanceled();

            DefaultHassClientMock.VerifyCallServiceTimes("toggle", Times.Once());
            DefaultHassClientMock.VerifyCallService("light", "toggle", ("entity_id", "light.correct_entity"));
        }
Esempio n. 17
0
        public async Task CameraSnapshotCallsCorrectServiceCall()
        {
            // ARRANGE
            var entityId     = "camera.camera1";
            var service_call = "snapshot";

            // ACT
            await DefaultDaemonApp
            .Camera(entityId)
            .Snapshot("filename")
            .ExecuteAsync();

            // ASSERT
            DefaultHassClientMock.VerifyCallServiceTimes(service_call, Times.Once());
            DefaultHassClientMock.VerifyCallService("camera", service_call,
                                                    ("filename", "filename"),
                                                    ("entity_id", entityId)
                                                    );
        }
Esempio n. 18
0
        public async Task MediaPlayersFuncPlayCallsCorrectServiceCall()
        {
            // ARRANGE
            DefaultDaemonHost.InternalState["media_player.player"] = new EntityState
            {
                EntityId = "media_player.player",
                State    = "off"
            };

            // ACT
            await DefaultDaemonApp
            .MediaPlayers(n => n.EntityId == "media_player.player")
            .Play()
            .ExecuteAsync();

            // ASSERT
            DefaultHassClientMock.VerifyCallServiceTimes("media_play", Times.Once());
            DefaultHassClientMock.VerifyCallService("media_player", "media_play", ("entity_id", "media_player.player"));
        }
Esempio n. 19
0
        public async Task EntityOnStateChangedLamdaWithMultipleEntitiesCallsCorrectServiceCall()
        {
            // ARRANGE
            DefaultHassClientMock.AddChangedEvent("binary_sensor.pir", "off", "on");

            var cancelSource  = DefaultHassClientMock.GetSourceWithTimeout();
            var MotionEnabled = true;

            DefaultDaemonApp
            .Entities(new string[] { "binary_sensor.pir", "binary_sensor-pir2" })
            .WhenStateChange((to, from) => @from?.State == "off" && to?.State == "on" && MotionEnabled)
            .UseEntity("light.correct_entity")
            .Toggle()
            .Execute();

            await RunDefauldDaemonUntilCanceled();

            DefaultHassClientMock.VerifyCallServiceTimes("toggle", Times.Once());
            DefaultHassClientMock.VerifyCallService("light", "toggle", ("entity_id", "light.correct_entity"));
        }
Esempio n. 20
0
        public async Task CameraPlayStreamCallsCorrectServiceCall()
        {
            // ARRANGE
            var entityId     = "camera.camera1";
            var service_call = "play_stream";

            // ACT
            await DefaultDaemonApp
            .Camera(entityId)
            .PlayStream("media_player.player", "anyformat")
            .ExecuteAsync();

            // ASSERT
            DefaultHassClientMock.VerifyCallServiceTimes(service_call, Times.Once());
            DefaultHassClientMock.VerifyCallService("camera", service_call,
                                                    ("media_player", "media_player.player"),
                                                    ("format", "anyformat"),
                                                    ("entity_id", entityId)
                                                    );
        }
Esempio n. 21
0
        public async Task TimerEntitiesLambdaEveryShouldCallServiceCorrectNumberOfTimes()
        {
            // ARRANGE
            DefaultDaemonHost.InternalState.Add("light.correct_light", new EntityState
            {
                EntityId = "light.correct_light"
            });

            DefaultDaemonHost
            .Timer()
            .Every(TimeSpan.FromMilliseconds(20))
            .Entities(n => n.EntityId == "light.correct_light")
            .TurnOn()
            .Execute();

            await RunDefauldDaemonUntilCanceled();

            // ASSERT
            DefaultHassClientMock.VerifyCallServiceTimes("turn_on", Times.AtLeast(4));
            DefaultHassClientMock.VerifyCallService("light", "turn_on", ("entity_id", "light.correct_light"));
        }
Esempio n. 22
0
        public async Task CameraRecordCallsCorrectServiceCall()
        {
            // ARRANGE
            var entityId     = "camera.camera1";
            var service_call = "record";

            // ACT
            await DefaultDaemonApp
            .Camera(entityId)
            .Record("filename", 1, 2)
            .ExecuteAsync();

            // ASSERT
            DefaultHassClientMock.VerifyCallServiceTimes(service_call, Times.Once());
            DefaultHassClientMock.VerifyCallService("camera", service_call,
                                                    ("filename", "filename"),
                                                    ("duration", 1),
                                                    ("lookback", 2),
                                                    ("entity_id", entityId)
                                                    );
        }
Esempio n. 23
0
        public async Task CamerasFuncDisableMotionDetectionCallsCorrectServiceCall()
        {
            // ARRANGE
            var entityId     = "camera.camera1";
            var service_call = "disable_motion_detection";

            DefaultDaemonHost.InternalState["camera.camera1"] = new EntityState
            {
                EntityId = entityId,
                State    = "on"
            };

            // ACT
            await DefaultDaemonApp
            .Cameras(n => n.EntityId == entityId)
            .DisableMotionDetection()
            .ExecuteAsync();

            // ASSERT
            DefaultHassClientMock.VerifyCallServiceTimes(service_call, Times.Once());
            DefaultHassClientMock.VerifyCallService("camera", service_call, ("entity_id", entityId));
        }