From 257a7bfcef90a7b0fee1b9b6830632c2791bda93 Mon Sep 17 00:00:00 2001 From: helto4real Date: Sat, 2 May 2020 07:29:06 +0200 Subject: [PATCH 1/2] Possible to disable load local assemblies --- src/App/NetDaemon.App/NetDaemon.App.csproj | 2 +- .../NetDaemon.Daemon/NetDaemon.Daemon.csproj | 2 +- .../DaemonRunner/DaemonRunner.csproj | 2 +- .../DaemonRunner/Service/App/CodeManager.cs | 4 ++++ .../Fluent/FluentTests.cs | 24 ++++++++++++++++++- 5 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/App/NetDaemon.App/NetDaemon.App.csproj b/src/App/NetDaemon.App/NetDaemon.App.csproj index 65fafcd59..3b566031a 100644 --- a/src/App/NetDaemon.App/NetDaemon.App.csproj +++ b/src/App/NetDaemon.App/NetDaemon.App.csproj @@ -23,7 +23,7 @@ - + diff --git a/src/Daemon/NetDaemon.Daemon/NetDaemon.Daemon.csproj b/src/Daemon/NetDaemon.Daemon/NetDaemon.Daemon.csproj index d3859cb88..f5befce22 100644 --- a/src/Daemon/NetDaemon.Daemon/NetDaemon.Daemon.csproj +++ b/src/Daemon/NetDaemon.Daemon/NetDaemon.Daemon.csproj @@ -20,7 +20,7 @@ - + diff --git a/src/DaemonRunner/DaemonRunner/DaemonRunner.csproj b/src/DaemonRunner/DaemonRunner/DaemonRunner.csproj index 470378463..3e8ea4b42 100644 --- a/src/DaemonRunner/DaemonRunner/DaemonRunner.csproj +++ b/src/DaemonRunner/DaemonRunner/DaemonRunner.csproj @@ -21,7 +21,7 @@ - + diff --git a/src/DaemonRunner/DaemonRunner/Service/App/CodeManager.cs b/src/DaemonRunner/DaemonRunner/Service/App/CodeManager.cs index 34eef7863..07292efbb 100644 --- a/src/DaemonRunner/DaemonRunner/Service/App/CodeManager.cs +++ b/src/DaemonRunner/DaemonRunner/Service/App/CodeManager.cs @@ -427,6 +427,10 @@ public async Task> InstanceAndInitApplications(INetDa private void LoadLocalAssemblyApplicationsForDevelopment() { + var disableLoadLocalAssemblies = Environment.GetEnvironmentVariable("HASS_DISABLE_LOCAL_ASM"); + if (disableLoadLocalAssemblies is object && disableLoadLocalAssemblies == "true") + return; + // Get daemon apps in entry assembly (mainly for development) var apps = Assembly.GetEntryAssembly()?.GetTypes().Where(type => type.IsClass && type.IsSubclassOf(typeof(NetDaemonApp))); if (apps != null) diff --git a/tests/NetDaemon.Daemon.Tests/Fluent/FluentTests.cs b/tests/NetDaemon.Daemon.Tests/Fluent/FluentTests.cs index 3197c0671..2279758f3 100644 --- a/tests/NetDaemon.Daemon.Tests/Fluent/FluentTests.cs +++ b/tests/NetDaemon.Daemon.Tests/Fluent/FluentTests.cs @@ -77,7 +77,29 @@ public async Task EntityOnStateChangedLamdaTurnOnLightCallsCorrectServiceCall() } [Fact] - public async Task EntityOnStateChangedLamdaToggleLightCallsCorrectServiceCall() + 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")); + } + + [Fact] + public async Task OneEntityWithSeveralShouldCallsCorrectServiceCall() { // ARRANGE DefaultHassClientMock.AddChangedEvent("binary_sensor.pir", "off", "on"); From 4d70855fa358133a7b1a57c328689d1e6f37c35a Mon Sep 17 00:00:00 2001 From: helto4real Date: Sat, 2 May 2020 07:34:30 +0200 Subject: [PATCH 2/2] Upgraded moq dep --- tests/NetDaemon.Daemon.Tests/NetDaemon.Daemon.Tests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/NetDaemon.Daemon.Tests/NetDaemon.Daemon.Tests.csproj b/tests/NetDaemon.Daemon.Tests/NetDaemon.Daemon.Tests.csproj index e5a7e4839..9c2b3e903 100644 --- a/tests/NetDaemon.Daemon.Tests/NetDaemon.Daemon.Tests.csproj +++ b/tests/NetDaemon.Daemon.Tests/NetDaemon.Daemon.Tests.csproj @@ -17,7 +17,7 @@ all - + all