@@ -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