Skip to content

Fix inverted app enable/disable state write - #1445

Merged
helto4real merged 1 commit into
net-daemon:mainfrom
DevJasperNL:fix/app-state-inverted-write
Sep 5, 2026
Merged

Fix inverted app enable/disable state write#1445
helto4real merged 1 commit into
net-daemon:mainfrom
DevJasperNL:fix/app-state-inverted-write

Conversation

@DevJasperNL

Copy link
Copy Markdown
Contributor

Proposed change

AppStateManager.SaveStateAsync only calls IAppStateRepository.UpdateAsync when the requested ApplicationState differs from the current input_boolean state, but it passed the current isEnabled value instead of the desired one. As a result every real write did the opposite of what was requested:

  • SaveStateAsync(id, Enabled) while the helper is off sent input_boolean.turn_off
  • SaveStateAsync(id, Disabled) while the helper is on sent input_boolean.turn_on

This PR passes state == ApplicationState.Enabled to UpdateAsync so the helper is set to the desired state.

The existing AppStateManagerTests only verified that some call_service command was sent, which is why this slipped through. The two affected tests now assert the exact domain and service (input_boolean.turn_off / input_boolean.turn_on) and that it is sent exactly once. Both tests fail against the previous code and pass with the fix.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (which adds functionality to an existing integration)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:

Found during a code review of the runtime; no issue was filed for it. The bug only affects users who opt in via AddNetDaemonStateManager().

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • The code compiles without warnings (code quality check)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration are added/changed:

@codecov

codecov Bot commented Sep 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83%. Comparing base (993cd31) to head (65e77f6).

Additional details and impacted files
@@         Coverage Diff          @@
##           main   #1445   +/-   ##
====================================
  Coverage    82%     83%           
====================================
  Files       201     201           
  Lines      4165    4165           
  Branches    485     485           
====================================
+ Hits       3450    3461   +11     
+ Misses      509     499   -10     
+ Partials    206     205    -1     
Flag Coverage Δ
unittests 83% <100%> (+<1%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014w4cLiriBNpmBbY1Xpw8gV
@helto4real
helto4real force-pushed the fix/app-state-inverted-write branch from b48aeb5 to 65e77f6 Compare September 5, 2026 10:27

@helto4real helto4real left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix correctly persists the requested enabled state, and the strengthened assertions cover both turn_on and turn_off. All 50 runtime tests passed on the reviewed pre-rebase commit; the diff is unchanged after rebasing onto current main. Approved, with merge pending the required CI checks on the rebased commit.

@helto4real
helto4real enabled auto-merge (squash) September 5, 2026 10:28
@helto4real
helto4real merged commit 7ef17c2 into net-daemon:main Sep 5, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants