Skip to content

Commit

Permalink
[netatmo] Ensure expiresAt is usable (openhab#17553)
Browse files Browse the repository at this point in the history
* Ensure expiresAt is usable

Signed-off-by: Gaël L'hopital <[email protected]>
  • Loading branch information
clinique authored Oct 13, 2024
1 parent a03ed48 commit 1e04957
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,15 @@ public class HomeEvent extends Event {
public class NAEventsDataResponse extends ApiResponse<BodyResponse<Home>> {
}

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;
}
}

Expand Down

0 comments on commit 1e04957

Please sign in to comment.