From 1e04957cef6c6abdf76b0c77abb2f1ea6f80fe56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABl=20L=27hopital?= Date: Sun, 13 Oct 2024 11:50:27 +0200 Subject: [PATCH] [netatmo] Ensure expiresAt is usable (#17553) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Ensure expiresAt is usable Signed-off-by: Gaƫl L'hopital --- .../binding/netatmo/internal/api/dto/HomeEvent.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/api/dto/HomeEvent.java b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/api/dto/HomeEvent.java index 58b3607a0c455..0ec894b756909 100644 --- a/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/api/dto/HomeEvent.java +++ b/bundles/org.openhab.binding.netatmo/src/main/java/org/openhab/binding/netatmo/internal/api/dto/HomeEvent.java @@ -37,10 +37,15 @@ public class HomeEvent extends Event { public class NAEventsDataResponse extends ApiResponse> { } - private record Snapshot(String url, ZonedDateTime expiresAt) { - // If the snapshot is expired we consider it as not available, so do not provide the url + private record Snapshot(@Nullable String url, @Nullable ZonedDateTime expiresAt) { public @Nullable String url() { - return expiresAt.isAfter(ZonedDateTime.now().withZoneSameInstant(expiresAt.getZone())) ? url : null; + ZonedDateTime expires = expiresAt; + // If no expiration data provided, lets consider it is available + if (expires == null) { + return url; + } + // If the snapshot is expired we consider it as not available, so do not provide the url + return expires.isAfter(ZonedDateTime.now().withZoneSameInstant(expires.getZone())) ? url : null; } }