Skip to content

fix: ignore state changes reported while a controller is being restored - #1133

Merged
bwp91 merged 2 commits into
homebridge:latestfrom
seydx:controller-storage-fix
Oct 19, 2026
Merged

bwp91 merged 2 commits into
homebridge:latestfrom
seydx:controller-storage-fix

Conversation

@seydx

@seydx seydx commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

Small one, found while working on the secure video controller but not specific to it.

What happens

ControllerStorage.restoreController calls controller.deserialize(), and most controllers restore their state through updateCharacteristic. That emits CHANGE. A controller listening on its own characteristics (or on a service it shares with another controller) reports a state change from inside the restore, handleStateChange serialises the controller mid-way and overwrites the stored data with the partially restored state. Whatever the controller restores after that point is gone on the next save.

CameraController doesn't trip over this because its listeners only react to HAP writes, but any SerializableController that uses CHANGE listeners does.

Fix

A restoring flag on ControllerStorage, set around deserialize() and around the initial restore loop in init(). State changes reported while it's set are ignored. The characteristics keep their restored values, only the write-back is skipped.

Test

ControllerStorage.spec.ts restores a controller that reports a state change halfway through its deserialize() and checks that the stored data is still complete, and that a real state change afterwards is picked up as usual.

@hjdhjd
hjdhjd self-requested a review October 15, 2026 16:27
Comment thread src/lib/model/ControllerStorage.ts Resolved
@bwp91

bwp91 commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

@seydx looks good, ive made just one comment

@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 39318154956

Coverage increased (+0.2%) to 66.966%

Details

  • Coverage increased (+0.2%) from the base build.
  • Patch coverage: 13 of 13 lines across 1 file are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 9681
Covered Lines: 6799
Line Coverage: 70.23%
Relevant Branches: 3463
Covered Branches: 2003
Branch Coverage: 57.84%
Branches in Coverage %: Yes
Coverage Strength: 365.88 hits per line

💛 - Coveralls

@bwp91
bwp91 merged commit 321015d into homebridge:latest Oct 19, 2026
16 checks passed
@bwp91

bwp91 commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

Hi @seydx
This change has been included in the v2.2.4-beta series and will be included in the upcoming v2.2.4 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants