From 1a6f5b51589553266a8f06a4c1846e73c40f7ab6 Mon Sep 17 00:00:00 2001 From: Christoph Weitkamp Date: Tue, 8 Dec 2020 20:07:24 +0100 Subject: [PATCH] [icalendar] Reload calendar file asynchronously (#9227) * Reload calendar file asynchronously * Incorporated comments from review Signed-off-by: Christoph Weitkamp --- .../internal/handler/ICalendarHandler.java | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/bundles/org.openhab.binding.icalendar/src/main/java/org/openhab/binding/icalendar/internal/handler/ICalendarHandler.java b/bundles/org.openhab.binding.icalendar/src/main/java/org/openhab/binding/icalendar/internal/handler/ICalendarHandler.java index 384d60002..a32c22c79 100644 --- a/bundles/org.openhab.binding.icalendar/src/main/java/org/openhab/binding/icalendar/internal/handler/ICalendarHandler.java +++ b/bundles/org.openhab.binding.icalendar/src/main/java/org/openhab/binding/icalendar/internal/handler/ICalendarHandler.java @@ -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 {