Skip to content

Commit b581ba7

Browse files
committed
chore: add HKSV-DEBUG diagnostic logging for issue #3928
1 parent a345cb6 commit b581ba7

4 files changed

Lines changed: 67 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22

33
All notable changes to `@homebridge/hap-nodejs` will be documented in this file. This project tries to adhere to [Semantic Versioning](http://semver.org/).
44

5+
## v2.1.6 (Pending Release)
6+
7+
### Changes
8+
9+
- chore: add HKSV-DEBUG diagnostic logging for issue #3928
10+
11+
### Homebridge Dependencies
12+
13+
- `@homebridge/ciao` @ `v1.3.8`
14+
- `@homebridge/dbus-native` @ `v0.7.5`
15+
- `bonjour-hap` @ `v3.10.2`
16+
517
## v2.1.5 (2026-05-05)
618

719
### Changes

src/lib/Accessory.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ export class Accessory extends EventEmitter {
434434
/**
435435
* @private Private API.
436436
*/
437-
controllerStorage: ControllerStorage = new ControllerStorage(this);
437+
controllerStorage!: ControllerStorage;
438438
/**
439439
* @private Private API.
440440
*/
@@ -462,6 +462,8 @@ export class Accessory extends EventEmitter {
462462
assert(uuid.isValid(UUID), "UUID '" + UUID + "' is not a valid UUID. Try using the provided 'generateUUID' function to create a " +
463463
"valid UUID from any arbitrary string, like a serial number.");
464464

465+
this.controllerStorage = new ControllerStorage(this);
466+
465467
// create our initial "Accessory Information" Service that all Accessories are expected to have
466468
checkName(this.displayName, "Name", displayName);
467469
this.addService(Service.AccessoryInformation)
@@ -1107,7 +1109,12 @@ export class Accessory extends EventEmitter {
11071109
}
11081110
service.setCharacteristic(Characteristic.Version, CiaoAdvertiser.protocolVersionService);
11091111

1112+
console.log("[HKSV-DEBUG] Accessory.publish: name=%s UUID=%s lastKnownUsername=%s info.username=%s willCleanup=%s",
1113+
this.displayName, this.UUID, this.lastKnownUsername, info.username,
1114+
!!(this.lastKnownUsername && this.lastKnownUsername !== info.username));
1115+
11101116
if (this.lastKnownUsername && this.lastKnownUsername !== info.username) { // username changed since last publish
1117+
console.log("[HKSV-DEBUG] Accessory.publish: WIPING old data for username %s (changed to %s)", this.lastKnownUsername, info.username);
11111118
Accessory.cleanupAccessoryData(this.lastKnownUsername); // delete old Accessory data
11121119
}
11131120

src/lib/camera/RecordingManagement.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,13 @@ export class RecordingManagement {
609609

610610
const changed = this.selectedConfiguration?.base64 !== value;
611611

612+
console.log(
613+
"[HKSV-DEBUG] handleSelectedCameraRecordingConfigurationWrite: HomeKit pushed selectedConfig (changed=%s, hasStateChangeDelegate=%s, base64Len=%d)",
614+
changed,
615+
!!this.stateChangeDelegate,
616+
typeof value === "string" ? value.length : -1,
617+
);
618+
612619
this.selectedConfiguration = {
613620
parsed: configuration,
614621
base64: value,
@@ -836,13 +843,24 @@ export class RecordingManagement {
836843

837844
// we only restore the `selectedConfiguration` if our supported configuration hasn't changed.
838845
const currentConfigurationHash = this.computeConfigurationHash(serialized.configurationHash.algorithm);
846+
847+
console.log("[HKSV-DEBUG] RecordingManagement.deserialize: hasSavedSelectedConfig=%s, savedHash=%s, currentHash=%s, hashMatch=%s, recordingActive=%s",
848+
!!serialized.selectedConfiguration,
849+
serialized.configurationHash?.hash?.slice(0, 12),
850+
currentConfigurationHash.slice(0, 12),
851+
currentConfigurationHash === serialized.configurationHash?.hash,
852+
serialized.recordingActive);
853+
839854
if (serialized.selectedConfiguration) {
840855
if (currentConfigurationHash === serialized.configurationHash.hash) {
841856
this.selectedConfiguration = {
842857
base64: serialized.selectedConfiguration,
843858
parsed: this.parseSelectedConfiguration(serialized.selectedConfiguration),
844859
};
845860
} else {
861+
console.log(
862+
"[HKSV-DEBUG] RecordingManagement.deserialize: DISCARDING saved selectedConfiguration — supportedConfiguration hash changed since last run",
863+
);
846864
changedState = true;
847865
}
848866
}
@@ -861,7 +879,10 @@ export class RecordingManagement {
861879

862880
try {
863881
if (this.selectedConfiguration) {
882+
console.log("[HKSV-DEBUG] RecordingManagement.deserialize: REPLAYING updateRecordingConfiguration to delegate");
864883
this.delegate.updateRecordingConfiguration(this.selectedConfiguration.parsed);
884+
} else {
885+
console.log("[HKSV-DEBUG] RecordingManagement.deserialize: NOT calling updateRecordingConfiguration (no selectedConfiguration to restore)");
865886
}
866887
if (serialized.recordingActive) {
867888
this.delegate.updateRecordingActive(serialized.recordingActive);

src/lib/model/ControllerStorage.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ export class ControllerStorage {
102102
public trackController(controller: SerializableController): void {
103103
controller.setupStateChangeDelegate(this.handleStateChange.bind(this, controller)); // setup delegate
104104

105+
console.log("[HKSV-DEBUG] ControllerStorage.trackController: accUUID=%s ctrlId=%s initialized=%s",
106+
this.accessoryUUID, controller.controllerId(), this.initialized);
107+
105108
if (!this.initialized) { // track controller if data isn't loaded yet
106109
this.trackedControllers.push(controller);
107110
} else {
@@ -132,6 +135,9 @@ export class ControllerStorage {
132135
const id = controller.controllerId();
133136
const serialized = controller.serialize();
134137

138+
console.log("[HKSV-DEBUG] ControllerStorage.handleStateChange: accUUID=%s ctrlId=%s hasSerialized=%s initialized=%s hasParent=%s",
139+
this.accessoryUUID, id, !!serialized, this.initialized, !!this.parent);
140+
135141
if (!serialized) { // can be undefined when controller wishes to delete data
136142
delete this.controllerData[id];
137143
} else {
@@ -150,6 +156,8 @@ export class ControllerStorage {
150156
// run save data "async", as handleStateChange call will probably always be caused by a http request
151157
// this should improve our response time
152158
this.enqueueSaveRequest(100);
159+
} else {
160+
console.log("[HKSV-DEBUG] ControllerStorage.handleStateChange: NOT enqueuing save — storage not yet initialized (acc %s)", this.accessoryUUID);
153161
}
154162
}
155163

@@ -160,6 +168,10 @@ export class ControllerStorage {
160168
}
161169

162170
const controllerData = this.controllerData[controller.controllerId()];
171+
172+
console.log("[HKSV-DEBUG] ControllerStorage.restoreController: accUUID=%s ctrlId=%s hasStoredData=%s",
173+
this.accessoryUUID, controller.controllerId(), !!controllerData);
174+
163175
if (controllerData) {
164176
try {
165177
controller.deserialize(controllerData.data);
@@ -230,6 +242,14 @@ export class ControllerStorage {
230242
delete saved.accessories[this.accessoryUUID];
231243
}
232244

245+
console.log("[HKSV-DEBUG] ControllerStorage.load: username=%s key=%s fileExisted=%s thisAccUUID=%s ownDataEntries=%s otherAccUUIDsInFile=%j",
246+
username,
247+
key,
248+
!!saved,
249+
this.accessoryUUID,
250+
ownData ? ownData.length : "none",
251+
saved ? Object.keys(saved.accessories) : []);
252+
233253
this.init(ownData);
234254

235255
if (this.linkedAccessories) {
@@ -291,9 +311,15 @@ export class ControllerStorage {
291311
accessories: accessoryData,
292312
};
293313

314+
console.log("[HKSV-DEBUG] ControllerStorage.save: WRITE %s — accUUIDs=%j ctrlIdsPerAcc=%j",
315+
key,
316+
Object.keys(accessoryData),
317+
Object.fromEntries(Object.entries(accessoryData).map(([acc, entries]) => [acc, entries.map(e => e.type)])));
318+
294319
this.fileCreated = true;
295320
HAPStorage.storage().setItemSync(key, saved);
296321
} else if (this.fileCreated) {
322+
console.log("[HKSV-DEBUG] ControllerStorage.save: REMOVE %s (no controller data left)", key);
297323
this.fileCreated = false;
298324
HAPStorage.storage().removeItemSync(key);
299325
}

0 commit comments

Comments
 (0)