[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

View 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 {