]> git.basschouten.com Git - openhab-addons.git/commitdiff
[icalendar] Fix race condition while initialization of EventFilterHandler (#9230)
authorMichael Wodniok <michi@noorganization.org>
Sat, 5 Dec 2020 05:35:14 +0000 (06:35 +0100)
committerGitHub <noreply@github.com>
Sat, 5 Dec 2020 05:35:14 +0000 (21:35 -0800)
* [icalendar] Fix race condition while initialization of EventFilterHandler

Should fix #9029. The channels do not get updated as the known channels by the binding where only updated if Bridge was already online while initializing EventFilterHandler.
Also added a bit more output.

* [icalendar] use implicit conversion to string for logging

Signed-off-by: Michael Wodniok <michi@noorganization.org>
Co-authored-by: Connor Petty <mistercpp2000+gitsignoff@gmail.com>
bundles/org.openhab.binding.icalendar/src/main/java/org/openhab/binding/icalendar/internal/handler/EventFilterHandler.java
bundles/org.openhab.binding.icalendar/src/main/java/org/openhab/binding/icalendar/internal/handler/ICalendarHandler.java

index ac108ec08c1f76dbc7a9a6d7f70186b8768186e8..b2ed561bf0f1ccc7c04134c0ba9965ab0bd9f8b6 100644 (file)
@@ -95,9 +95,7 @@ public class EventFilterHandler extends BaseThingHandler implements CalendarUpda
     @Override
     public void handleCommand(ChannelUID channelUID, Command command) {
         if (command instanceof RefreshType) {
-            if (initFinished) {
-                updateStates();
-            }
+            updateStates();
         }
     }
 
@@ -121,14 +119,13 @@ public class EventFilterHandler extends BaseThingHandler implements CalendarUpda
         }
         configuration = config;
 
+        updateChannelSet(config);
+        initFinished = true;
         if (iCalendarBridge.getStatus() != ThingStatus.ONLINE) {
             updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE);
             return;
-        } else {
-            updateChannelSet(config);
-            updateStates();
         }
-        initFinished = true;
+        updateStates();
     }
 
     @Override
@@ -257,6 +254,10 @@ public class EventFilterHandler extends BaseThingHandler implements CalendarUpda
      * Updates all states and channels. Reschedules an update if no error occurs.
      */
     private void updateStates() {
+        if (!initFinished) {
+            logger.debug("Ignoring call for updating states as this instance is not initialized yet.");
+            return;
+        }
         final Bridge iCalendarBridge = getBridge();
         if (iCalendarBridge == null) {
             logger.debug("Bridge not instantiated!");
index deb7c4add60c937dd008cdd32509969c4eebb4e1..384d60002776eebf1e566cb2e01b4361d8dadbd5 100644 (file)
@@ -183,6 +183,7 @@ public class ICalendarHandler extends BaseBridgeHandler implements CalendarUpdat
                 ThingHandler handler = childThing.getHandler();
                 if (handler instanceof CalendarUpdateListener) {
                     try {
+                        logger.trace("Notifying {} about fresh calendar.", handler.getThing().getUID());
                         ((CalendarUpdateListener) handler).onCalendarUpdated();
                     } catch (Exception e) {
                         logger.trace("The update of a child handler failed. Ignoring.", e);