Skip to content

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

Open
seydx wants to merge 1 commit into
homebridge:latestfrom
seydx:controller-storage-fix
Open

seydx wants to merge 1 commit into
homebridge:latestfrom
seydx:controller-storage-fix

Conversation

@seydx

@seydx seydx commented Sep 15, 2026

Copy link
Copy Markdown

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.

This branch has not been deployed

No deployments
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.

1 participant