[icalendar] Reload calendar file asynchronously (#9227)

* Reload calendar file asynchronously
* Incorporated comments from review

Signed-off-by: Christoph Weitkamp <github@christophweitkamp.de>
This commit is contained in:
Christoph Weitkamp 2020-12-08 20:07:24 +01:00 committed by GitHub
parent 3eda5ebbc9
commit 1a6f5b5158
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 10 deletions

View File

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