@@ -243,9 +243,6 @@ private void fetchAccessories() {
243243 * 'onThingOnline' methods (and its eventual overloaded implementations).
244244 */
245245 private void processBridgedThings () {
246- if (!bridgedThingsInitialized ()) {
247- logger .warn ("{} unexpected error: bridged Things not initialized." , thing .getUID ());
248- }
249246 onConnectedThingAccessoriesLoaded ();
250247 onThingOnline ();
251248 }
@@ -291,10 +288,9 @@ public void initialize() {
291288 if (alreadyAtStartLevelComplete ()) {
292289 // schedule connection attempt immediately
293290 scheduleConnectionAttempt ();
294- } else {
291+ } else if ( bundle . getBundleContext () instanceof BundleContext ctx ) {
295292 // delay connection attempt until STARTLEVEL_COMPLETE is signalled via receive() method below
296- BundleContext context = bundle .getBundleContext ();
297- eventSubscription = context .registerService (EventSubscriber .class .getName (), this , null );
293+ eventSubscription = ctx .registerService (EventSubscriber .class .getName (), this , null );
298294 }
299295 }
300296 updateStatus (ThingStatus .UNKNOWN );
@@ -306,14 +302,16 @@ public void initialize() {
306302 * Note: STARTLEVEL_COMPLETE means all Thing handlers are instantiated and their initialize() methods have
307303 * been called, and the registries for item, thing, and item-channel-links have all been loaded.
308304 */
309- private boolean alreadyAtStartLevelComplete () {
310- BundleContext context = bundle .getBundleContext ();
311- ServiceReference <StartLevelService > reference = context .getServiceReference (StartLevelService .class );
312- if (reference != null && context .getService (reference ) instanceof StartLevelService service ) {
313- try {
314- return service .getStartLevel () >= StartLevelService .STARTLEVEL_COMPLETE ;
315- } finally {
316- context .ungetService (reference );
305+ protected boolean alreadyAtStartLevelComplete () {
306+ if (bundle .getBundleContext () instanceof BundleContext ctx ) {
307+ if (ctx .getServiceReference (StartLevelService .class ) instanceof ServiceReference <StartLevelService > ref ) {
308+ if (ctx .getService (ref ) instanceof StartLevelService svc ) {
309+ try {
310+ return svc .getStartLevel () >= StartLevelService .STARTLEVEL_COMPLETE ;
311+ } finally {
312+ ctx .ungetService (ref );
313+ }
314+ }
317315 }
318316 }
319317 return false ;
@@ -416,12 +414,11 @@ private String normalizePairingCode(String input) throws IllegalArgumentExceptio
416414 protected void scheduleConnectionAttempt () {
417415 if (getBridge () instanceof Bridge bridge && bridge .getHandler () instanceof HomekitBridgeHandler bridgeHandler ) {
418416 bridgeHandler .scheduleConnectionAttempt ();
419- } else {
420- ScheduledFuture <?> task = connectionAttemptTask ;
421- if (task == null || task .isDone () || task .isCancelled ()) {
422- connectionAttemptTask = scheduler .schedule (this ::attemptConnect , connectionAttemptDelay ,
423- TimeUnit .SECONDS );
424- }
417+ return ;
418+ }
419+ ScheduledFuture <?> task = connectionAttemptTask ;
420+ if (task == null || task .isDone () || task .isCancelled ()) {
421+ connectionAttemptTask = scheduler .schedule (this ::attemptConnect , connectionAttemptDelay , TimeUnit .SECONDS );
425422 }
426423 }
427424
@@ -687,7 +684,11 @@ protected void createProperties() {
687684 *
688685 * @param enable true to enable events, false to disable
689686 */
690- private void enableEvents (boolean enable ) {
687+ protected void enableEvents (boolean enable ) {
688+ if (getBridge () instanceof Bridge bridge && bridge .getHandler () instanceof HomekitBridgeHandler bridgeHandler ) {
689+ bridgeHandler .enableEvents (true );
690+ return ;
691+ }
691692 try {
692693 enableEventsOrThrow (enable );
693694 } catch (InterruptedException e ) {
@@ -772,12 +773,6 @@ private synchronized void refresh() {
772773 }
773774 }
774775
775- /**
776- * Checks if all bridged accessory things have the reached status UNKNOWN, OFFLINE, or ONLINE.
777- * Subclasses MUST override this to perform the check.
778- */
779- protected abstract boolean bridgedThingsInitialized ();
780-
781776 /**
782777 * Called when the connected thing has finished loading the accessories.
783778 * Subclasses MUST override this to perform any extra processing required.
@@ -863,11 +858,11 @@ private void cancelRefreshTasks() {
863858 protected void requestManualRefresh () {
864859 if (getBridge () instanceof Bridge bridge && bridge .getHandler () instanceof HomekitBridgeHandler bridgeHandler ) {
865860 bridgeHandler .requestManualRefresh ();
866- } else {
867- Future <?> task = manualRefreshTask ;
868- if ( task == null || task . isDone () || task . isCancelled ()) {
869- manualRefreshTask = scheduler . schedule ( this :: refresh , MANUAL_REFRESH_DELAY_SECONDS , TimeUnit . SECONDS );
870- }
861+ return ;
862+ }
863+ Future <?> task = manualRefreshTask ;
864+ if ( task == null || task . isDone () || task . isCancelled ()) {
865+ manualRefreshTask = scheduler . schedule ( this :: refresh , MANUAL_REFRESH_DELAY_SECONDS , TimeUnit . SECONDS );
871866 }
872867 }
873868
0 commit comments