Ejemplo n.º 1
0
        public async Task EntityOnStateChangedEntitiesLambdaTurnOnLightCallsCorrectServiceCall()
        {
            // ARRANGE
            await InitializeFakeDaemon().ConfigureAwait(false);



            // Fake the
            DefaultDaemonHost.InternalState["light.correct_entity"] = new EntityState
            {
                EntityId = "light.correct_entity"
            };

            DefaultDaemonApp
            .Entity("binary_sensor.pir")
            .WhenStateChange("on")
            .UseEntities(n => n.EntityId == "light.correct_entity")
            .TurnOn()
            .Execute();

            AddChangedEvent("binary_sensor.pir", "off", "on");
            await RunFakeDaemonUntilTimeout().ConfigureAwait(false);

            VerifyCallServiceTimes("turn_on", Times.Once());
            VerifyCallServiceTuple("light", "turn_on", ("entity_id", "light.correct_entity"));
        }
Ejemplo n.º 2
0
        public async Task EntityInAreaOnStateChangedShouldTurnOn()
        {
            // ARRANGE

            await InitializeFakeDaemon().ConfigureAwait(false);

            // Fake the state
            SetEntityState("light.ligth_in_area", area: "Area");

            // ACT
            DefaultDaemonApp
            .Entity("binary_sensor.pir")
            .WhenStateChange("on")
            .UseEntities(n => n.Area == "Area")
            .TurnOn()
            .Execute();

            // light.light_in_area is setup so it has area = Area
            AddChangedEvent("binary_sensor.pir", "off", "on");

            await RunFakeDaemonUntilTimeout().ConfigureAwait(false);

            // ASSERT
            VerifyCallServiceTimes("turn_on", Times.Once());
            VerifyCallServiceTuple("light", "turn_on", ("entity_id", "light.ligth_in_area"));
        }
Ejemplo n.º 3
0
        public async Task EntityOnStateChangedTurnOnLightCallsCorrectServiceCallButNoTurnOff()
        {
            // ARRANGE
            await InitializeFakeDaemon().ConfigureAwait(false);


            DefaultDaemonApp
            .Entity("binary_sensor.pir")
            .WhenStateChange("on")
            .UseEntity("light.correct_entity")
            .TurnOn()
            .Execute();

            DefaultDaemonApp
            .Entity("binary_sensor.pir")
            .WhenStateChange("off")
            .UseEntity("light.correct_entity")
            .TurnOff()
            .Execute();

            AddChangedEvent("binary_sensor.pir", "off", "on");
            await RunFakeDaemonUntilTimeout().ConfigureAwait(false);

            VerifyCallServiceTimes("turn_on", Times.Once());
            VerifyCallServiceTuple("light", "turn_on", ("entity_id", "light.correct_entity"));

            VerifyCallServiceTimes("turn_off", Times.Never());
        }
Ejemplo n.º 4
0
        public async Task MediaPlayerStopCallsCorrectServiceCall()
        {
            // ARRANGE
            // ACT
            await DefaultDaemonApp
            .MediaPlayer("media_player.player")
            .Stop()
            .ExecuteAsync();

            // ASSERT
            VerifyCallServiceTimes("media_stop", Times.Once());
            VerifyCallServiceTuple("media_player", "media_stop", ("entity_id", "media_player.player"));
        }
Ejemplo n.º 5
0
        public async Task TurnOnEntityCallsCorrectServiceCall()
        {
            // ARRANGE
            // ACT
            await DefaultDaemonApp
            .Entity("light.correct_entity")
            .TurnOn()
            .ExecuteAsync();

            // ASSERT
            VerifyCallServiceTimes("turn_on", Times.Once());
            VerifyCallServiceTuple("light", "turn_on", ("entity_id", "light.correct_entity"));
        }
Ejemplo n.º 6
0
        public async Task MediaPlayersPlayCallsCorrectServiceCall()
        {
            // ARRANGE
            // ACT
            await DefaultDaemonApp
            .MediaPlayers(new string[] { "media_player.player" })
            .Play()
            .ExecuteAsync();

            // ASSERT
            VerifyCallServiceTimes("media_play", Times.Once());
            VerifyCallServiceTuple("media_player", "media_play", ("entity_id", "media_player.player"));
        }
Ejemplo n.º 7
0
        public async Task CallServiceShouldCallCorrectFunction()
        {
            // ARRANGE
            await InitializeFakeDaemon().ConfigureAwait(false);

            var(dynObj, _) = GetDynamicObject(
                ("attr", "value"));

            // ACT
            DefaultDaemonRxApp.CallService("mydomain", "myservice", dynObj);
            await RunFakeDaemonUntilTimeout().ConfigureAwait(false);

            // ASSERT
            VerifyCallServiceTuple("mydomain", "myservice", ("attr", "value"));
        }
Ejemplo n.º 8
0
        public async Task InputSelectSetOptionIEnumerableShouldCallCorrectCallService()
        {
            // ARRANGE
            // ACT
            await DefaultDaemonApp
            .InputSelects(new string[] { "input_select.myselect" })
            .SetOption("option1")
            .ExecuteAsync();

            // ASSERT
            VerifyCallServiceTimes("select_option", Times.Once());
            VerifyCallServiceTuple("input_select", "select_option",
                                   ("entity_id", "input_select.myselect"),
                                   ("option", "option1"));
        }
Ejemplo n.º 9
0
        public async Task TurnOffMultipleEntityCallsCorrectServiceCall()
        {
            // ARRANGE

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

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

            VerifyCallServiceTuple("light", "turn_off", ("entity_id", "light.correct_entity"));
            VerifyCallServiceTuple("light", "turn_off", ("entity_id", "light.correct_entity2"));
        }
Ejemplo n.º 10
0
        public async Task OneEntityWithSeveralShouldCallsCorrectServiceCall()
        {
            // ARRANGE
            await InitializeFakeDaemon().ConfigureAwait(false);

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

            AddChangedEvent("binary_sensor.pir", "off", "on");
            await RunFakeDaemonUntilTimeout().ConfigureAwait(false);

            VerifyCallServiceTimes("toggle", Times.Once());
            VerifyCallServiceTuple("light", "toggle", ("entity_id", "light.correct_entity"));
        }
Ejemplo n.º 11
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
            VerifyCallServiceTimes("select_option", Times.Once());
            VerifyCallServiceTuple("input_select", "select_option",
                                   ("entity_id", "input_select.myselect"),
                                   ("option", "option1"));
        }
Ejemplo n.º 12
0
        public async Task TurnOnEntityWithMultipleAttributeCallsCorrectServiceCall()
        {
            // ARRANGE
            // ACT
            await DefaultDaemonApp
            .Entity("light.correct_entity")
            .TurnOn()
            .WithAttribute("brightness", 100)
            .WithAttribute("color_temp", 230)
            .ExecuteAsync();

            // ASSERT
            VerifyCallServiceTimes("turn_on", Times.Once());
            VerifyCallServiceTuple("light", "turn_on",
                                   ("brightness", 100),
                                   ("color_temp", 230),
                                   ("entity_id", "light.correct_entity"));
        }
Ejemplo n.º 13
0
        public async Task CameraSnapshotCallsCorrectServiceCall()
        {
            // ARRANGE
            var entityId     = "camera.camera1";
            var service_call = "snapshot";

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

            // ASSERT
            VerifyCallServiceTimes(service_call, Times.Once());
            VerifyCallServiceTuple("camera", service_call,
                                   ("filename", "filename"),
                                   ("entity_id", entityId)
                                   );
        }
Ejemplo n.º 14
0
        public async Task TurnOffEntityLamdaSelectionCallsCorrectServiceCall()
        {
            // ARRANGE
            await InitializeFakeDaemon().ConfigureAwait(false);

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

            // ASSERT

            VerifyCallServiceTimes("turn_off", Times.Exactly(2));
            VerifyCallServiceTuple("light", "turn_off", ("entity_id", "light.correct_entity"));
            VerifyCallServiceTuple("light", "turn_off", ("entity_id", "light.correct_entity2"));

            await RunFakeDaemonUntilTimeout().ConfigureAwait(false);
        }
Ejemplo n.º 15
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
            VerifyCallServiceTimes("media_play", Times.Once());
            VerifyCallServiceTuple("media_player", "media_play", ("entity_id", "media_player.player"));
        }
Ejemplo n.º 16
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
            VerifyCallServiceTimes(service_call, Times.Once());
            VerifyCallServiceTuple("camera", service_call,
                                   ("media_player", "media_player.player"),
                                   ("format", "anyformat"),
                                   ("entity_id", entityId)
                                   );
        }
Ejemplo n.º 17
0
        public async Task TurnOffEntityLambdaAttributeSelectionCallsCorrectServiceCall()
        {
            // ARRANGE
            await InitializeFakeDaemon().ConfigureAwait(false);

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

            // ASSERT

            VerifyCallServiceTimes("turn_off", Times.Exactly(3));
            VerifyCallServiceTuple("light", "turn_off", ("entity_id", "light.correct_entity"));
            VerifyCallServiceTuple("light", "turn_off", ("entity_id", "light.correct_entity2"));
            VerifyCallServiceTuple("switch", "turn_off", ("entity_id", "switch.correct_entity"));

            await RunFakeDaemonUntilTimeout().ConfigureAwait(false);
        }
Ejemplo n.º 18
0
        public async Task EntityOnStateChangedLamdaWithMultipleEntitiesCallsCorrectServiceCall()
        {
            // ARRANGE
            await InitializeFakeDaemon().ConfigureAwait(false);

            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();

            AddChangedEvent("binary_sensor.pir", "off", "on");
            await RunFakeDaemonUntilTimeout().ConfigureAwait(false);

            VerifyCallServiceTimes("toggle", Times.Once());
            VerifyCallServiceTuple("light", "toggle", ("entity_id", "light.correct_entity"));
        }
Ejemplo n.º 19
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
            VerifyCallServiceTimes(service_call, Times.Once());
            VerifyCallServiceTuple("camera", service_call,
                                   ("filename", "filename"),
                                   ("duration", 1),
                                   ("lookback", 2),
                                   ("entity_id", entityId)
                                   );
        }