From 65e77f67e2d70e9a03a499fdd894a50a02cb3581 Mon Sep 17 00:00:00 2001 From: Jasper Date: Sat, 5 Sep 2026 00:05:16 +0200 Subject: [PATCH] Fix inverted app enable/disable state write AppStateManager.SaveStateAsync passed the current enabled flag to UpdateAsync instead of the desired one, so enabling an app that was off sent turn_off and disabling an app that was on sent turn_on. Pass the desired state and assert the exact service in the tests. Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_014w4cLiriBNpmBbY1Xpw8gV --- .../Internal/AppStateManagerTests.cs | 12 ++++++------ .../NetDaemon.Runtime/Internal/AppStateManager.cs | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Runtime/NetDaemon.Runtime.Tests/Internal/AppStateManagerTests.cs b/src/Runtime/NetDaemon.Runtime.Tests/Internal/AppStateManagerTests.cs index c6d000291..402ccef5c 100644 --- a/src/Runtime/NetDaemon.Runtime.Tests/Internal/AppStateManagerTests.cs +++ b/src/Runtime/NetDaemon.Runtime.Tests/Internal/AppStateManagerTests.cs @@ -82,10 +82,10 @@ public async Task TestSaveStateAsyncReturnsCorrectStateDisabled() // ASSERT haConnectionMock.Verify(n => n.GetApiCallAsync("states/input_boolean.netdaemon_helloapp", It.IsAny())); - // It exists so it should turn it on + // It is on so it should turn it off haConnectionMock.Verify(n => - n.SendCommandAsync(It.IsAny(), - It.IsAny())); + n.SendCommandAsync(It.Is(c => c.Domain == "input_boolean" && c.Service == "turn_off"), + It.IsAny()), Times.Once); } [Fact] @@ -156,10 +156,10 @@ public async Task TestSetStateAsyncEnabled() // ASSERT haConnectionMock.Verify(n => n.GetApiCallAsync("states/input_boolean.netdaemon_helloapp", It.IsAny())); - // It exists so it should turn it on + // It is off so it should turn it on haConnectionMock.Verify(n => - n.SendCommandAsync(It.IsAny(), - It.IsAny())); + n.SendCommandAsync(It.Is(c => c.Domain == "input_boolean" && c.Service == "turn_on"), + It.IsAny()), Times.Once); } [Fact] diff --git a/src/Runtime/NetDaemon.Runtime/Internal/AppStateManager.cs b/src/Runtime/NetDaemon.Runtime/Internal/AppStateManager.cs index 13ca23373..a26e5b699 100644 --- a/src/Runtime/NetDaemon.Runtime/Internal/AppStateManager.cs +++ b/src/Runtime/NetDaemon.Runtime/Internal/AppStateManager.cs @@ -69,7 +69,7 @@ public async Task SaveStateAsync(string applicationId, ApplicationState state) (state == ApplicationState.Disabled && isEnabled) ) { - await appStateRepository.UpdateAsync(applicationId, isEnabled, _cancelTokenSource.Token) + await appStateRepository.UpdateAsync(applicationId, state == ApplicationState.Enabled, _cancelTokenSource.Token) .ConfigureAwait(false); } }