[icalendar] added last_update-channel (#9383)

last_update describes the last successful update of the calendar. Fixes #9301.

Signed-off-by: Michael Wodniok <michi@noorganization.org>
pull/9484/head
Michael Wodniok 2020-12-22 22:48:16 +01:00 committed by GitHub
parent 384bdff87c
commit 7b2bf4b95e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 0 deletions

View File

@ -59,6 +59,7 @@ They are all read-only.
| next_title | String | Title of the next event |
| next_start | DateTime | Start of the next event |
| next_end | DateTime | End of the next event |
| last_update | DateTime | The time and date of the last successful update of the calendar |
### Channels for `eventfilter`

View File

@ -40,6 +40,7 @@ public class ICalendarBindingConstants {
public static final String CHANNEL_NEXT_EVENT_TITLE = "next_title";
public static final String CHANNEL_NEXT_EVENT_START = "next_start";
public static final String CHANNEL_NEXT_EVENT_END = "next_end";
public static final String CHANNEL_LAST_UPDATE = "last_update";
// additional constants
public static final int HTTP_TIMEOUT_SECS = 60;

View File

@ -75,6 +75,7 @@ public class ICalendarHandler extends BaseBridgeHandler implements CalendarUpdat
private @Nullable AbstractPresentableCalendar runtimeCalendar;
private @Nullable ScheduledFuture<?> updateJobFuture;
private Instant updateStatesLastCalledTime;
private @Nullable Instant calendarDownloadedTime;
public ICalendarHandler(Bridge bridge, HttpClient httpClient, EventPublisher eventPublisher,
TimeZoneProvider tzProvider) {
@ -278,6 +279,7 @@ public class ICalendarHandler extends BaseBridgeHandler implements CalendarUpdat
final AbstractPresentableCalendar calendar = AbstractPresentableCalendar.create(fileStream);
runtimeCalendar = calendar;
rescheduleCalendarStateUpdate();
calendarDownloadedTime = Instant.ofEpochMilli(calendarFile.lastModified());
} catch (IOException | CalendarException e) {
logger.warn("Loading calendar failed: {}", e.getMessage());
return false;
@ -375,6 +377,11 @@ public class ICalendarHandler extends BaseBridgeHandler implements CalendarUpdat
updateState(CHANNEL_NEXT_EVENT_END, UnDefType.UNDEF);
}
final Instant lastUpdate = calendarDownloadedTime;
updateState(CHANNEL_LAST_UPDATE,
(lastUpdate != null ? new DateTimeType(lastUpdate.atZone(tzProvider.getTimeZone()))
: UnDefType.UNDEF));
// process all Command Tags in all Calendar Events which ENDED since updateStates was last called
// the END Event tags must be processed before the BEGIN ones
executeEventCommands(calendar.getJustEndedEvents(updateStatesLastCalledTime, now), CommandTagType.END);

View File

@ -66,6 +66,8 @@ channel-type.icalendar.event_next_start.label = Start des n
channel-type.icalendar.event_next_start.description = Start des nächsten Eintrags
channel-type.icalendar.event_next_end.label = Ende des nächsten Eintrags
channel-type.icalendar.event_next_end.description = Ende des nächsten Eintrags
channel-type.icalendar.last_update.label = Letztes Kalender-Update
channel-type.icalendar.last_update.description = Datum und Zeit des letzten erfolgreichen Kalender-Downloads
channel-group-type.icalendar.result.label = Ergebnis
channel-group-type.icalendar.result.description = Ergebnis, gefunden durch den Filter
channel-type.icalendar.result_start.label = Ergebnisstart

View File

@ -16,6 +16,7 @@
<channel id="next_title" typeId="event_next_title"/>
<channel id="next_start" typeId="event_next_start"/>
<channel id="next_end" typeId="event_next_end"/>
<channel id="last_update" typeId="last_update"/>
</channels>
<config-description>
@ -118,6 +119,12 @@
<description>Title of the found result in calendar</description>
<state readOnly="true"/>
</channel-type>
<channel-type id="last_update">
<item-type>DateTime</item-type>
<label>Last Update</label>
<description>The time the calendar was updated successfully last time</description>
<state readOnly="true"/>
</channel-type>
<channel-group-type id="result">
<label>Result Event</label>
<description>A resulting event found by filter</description>