]> git.basschouten.com Git - openhab-addons.git/commitdiff
[icalendar] Reload calendar file asynchronously (#9227)
authorChristoph Weitkamp <github@christophweitkamp.de>
Tue, 8 Dec 2020 19:07:24 +0000 (20:07 +0100)
committerGitHub <noreply@github.com>
Tue, 8 Dec 2020 19:07:24 +0000 (11:07 -0800)
* Reload calendar file asynchronously
* Incorporated comments from review

Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
bundles/org.openhab.binding.icalendar/src/main/java/org/openhab/binding/icalendar/internal/handler/ICalendarHandler.java

index 384d60002776eebf1e566cb2e01b4361d8dadbd5..a32c22c79b56e197b37cda2896a0df49b7dd691a 100644 (file)
@@ -120,8 +120,6 @@ public class ICalendarHandler extends BaseBridgeHandler implements CalendarUpdat
 
     @Override
     public void initialize() {
-        updateStatus(ThingStatus.UNKNOWN);
-
         final ICalendarConfiguration currentConfiguration = getConfigAs(ICalendarConfiguration.class);
         configuration = currentConfiguration;
 
@@ -154,14 +152,17 @@ public class ICalendarHandler extends BaseBridgeHandler implements CalendarUpdat
             }
             final long refreshTime = refreshTimeBD.longValue();
             if (calendarFile.isFile()) {
-                if (reloadCalendar()) {
-                    updateStatus(ThingStatus.ONLINE);
-                    updateStates();
-                    rescheduleCalendarStateUpdate();
-                } else {
-                    updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
-                            "The calendar seems to be configured correctly, but the local copy of calendar could not be loaded.");
-                }
+                updateStatus(ThingStatus.ONLINE);
+
+                scheduler.submit(() -> {
+                    // reload calendar file asynchronously
+                    if (reloadCalendar()) {
+                        updateStates();
+                    } else {
+                        updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR,
+                                "The calendar seems to be configured correctly, but the local copy of calendar could not be loaded.");
+                    }
+                });
                 pullJobFuture = scheduler.scheduleWithFixedDelay(regularPull, refreshTime, refreshTime,
                         TimeUnit.MINUTES);
             } else {