]> git.basschouten.com Git - openhab-addons.git/commitdiff
[icalendar] added last_update-channel (#9383)
authorMichael Wodniok <michi@noorganization.org>
Tue, 22 Dec 2020 21:48:16 +0000 (22:48 +0100)
committerGitHub <noreply@github.com>
Tue, 22 Dec 2020 21:48:16 +0000 (13:48 -0800)
last_update describes the last successful update of the calendar. Fixes #9301.

Signed-off-by: Michael Wodniok <michi@noorganization.org>
bundles/org.openhab.binding.icalendar/README.md
bundles/org.openhab.binding.icalendar/src/main/java/org/openhab/binding/icalendar/internal/ICalendarBindingConstants.java
bundles/org.openhab.binding.icalendar/src/main/java/org/openhab/binding/icalendar/internal/handler/ICalendarHandler.java
bundles/org.openhab.binding.icalendar/src/main/resources/OH-INF/i18n/icalendar_de.properties
bundles/org.openhab.binding.icalendar/src/main/resources/OH-INF/thing/thing-types.xml

index 217743531b480b08298cd892f0344eee2e0571b6..b2c98b71a49df5199ec8cdffe350c1e61176782e 100644 (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`
 
index df0d0845cd967a8657c9453d4727d98432830fb3..ad1aa6428762ad16781b0637c785e58ba9231bb1 100644 (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;
index e913fc2ed8db6087b7c6598bbd9cf80c4fe81cf7..06c5c60d3f7ac42d3733df80f0a2aee8f58861cb 100644 (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);
index e91507ebb3b49ec2583eec94fced03217e0a0014..85fd74cd53ef3d94c24c01dc5eda5cd9757a290b 100644 (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
index bf8cda4fdabfe973fb8bde96ed3c6277c0758320..8aaccfde118e8ece9365716b94321052b9ab963a 100644 (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>
                <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>