]> git.basschouten.com Git - openhab-addons.git/commitdiff
Restore type adapter for LocalDate (#14897)
authorMark Hilbush <mark@hilbush.com>
Fri, 28 Apr 2023 14:29:19 +0000 (10:29 -0400)
committerGitHub <noreply@github.com>
Fri, 28 Apr 2023 14:29:19 +0000 (16:29 +0200)
Signed-off-by: Mark Hilbush <mark@hilbush.com>
bundles/org.openhab.binding.sleepiq/src/main/java/org/openhab/binding/sleepiq/internal/api/dto/SleepDataSession.java
bundles/org.openhab.binding.sleepiq/src/main/java/org/openhab/binding/sleepiq/internal/api/impl/GsonGenerator.java
bundles/org.openhab.binding.sleepiq/src/main/java/org/openhab/binding/sleepiq/internal/api/impl/typeadapters/LocalDateTypeAdapter.java [new file with mode: 0644]

index be6cd94de7f8bb101e81e5309f995c61e84553d9..3d014595d63330b09756e74ed0da5812178282c8 100644 (file)
@@ -21,7 +21,7 @@ import com.google.gson.annotations.SerializedName;
  */
 public class SleepDataSession {
 
-    @SerializedName("avgSleepIQ")
+    @SerializedName("sleepQuotient")
     private Integer sessionAverageSleepIQ;
 
     @SerializedName("avgHeartRate")
index 1a0d1b1c7b187dfe9883c9336cf4f4a847fba96a..0571b3e6f3674e15d61ba2f83f6588b11d16aa7c 100644 (file)
@@ -12,6 +12,7 @@
  */
 package org.openhab.binding.sleepiq.internal.api.impl;
 
+import java.time.LocalDate;
 import java.time.ZonedDateTime;
 
 import org.eclipse.jdt.annotation.NonNullByDefault;
@@ -28,6 +29,7 @@ import org.openhab.binding.sleepiq.internal.api.impl.typeadapters.FoundationOutl
 import org.openhab.binding.sleepiq.internal.api.impl.typeadapters.FoundationOutletTypeAdapter;
 import org.openhab.binding.sleepiq.internal.api.impl.typeadapters.FoundationPositionTypeAdapter;
 import org.openhab.binding.sleepiq.internal.api.impl.typeadapters.FoundationPresetTypeAdapter;
+import org.openhab.binding.sleepiq.internal.api.impl.typeadapters.LocalDateTypeAdapter;
 import org.openhab.binding.sleepiq.internal.api.impl.typeadapters.SideTypeAdapter;
 import org.openhab.binding.sleepiq.internal.api.impl.typeadapters.SleepNumberRequestAdapter;
 import org.openhab.binding.sleepiq.internal.api.impl.typeadapters.TimeSinceTypeAdapter;
@@ -50,6 +52,7 @@ public class GsonGenerator {
     public static Gson create(boolean prettyPrint) {
         GsonBuilder builder = new GsonBuilder();
         builder.registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeTypeAdapter());
+        builder.registerTypeAdapter(LocalDate.class, new LocalDateTypeAdapter());
         builder.registerTypeAdapter(TimeSince.class, new TimeSinceTypeAdapter());
         builder.registerTypeAdapter(SleepNumberRequest.class, new SleepNumberRequestAdapter());
         builder.registerTypeAdapter(Side.class, new SideTypeAdapter());
diff --git a/bundles/org.openhab.binding.sleepiq/src/main/java/org/openhab/binding/sleepiq/internal/api/impl/typeadapters/LocalDateTypeAdapter.java b/bundles/org.openhab.binding.sleepiq/src/main/java/org/openhab/binding/sleepiq/internal/api/impl/typeadapters/LocalDateTypeAdapter.java
new file mode 100644 (file)
index 0000000..226f7f3
--- /dev/null
@@ -0,0 +1,30 @@
+/**
+ * Copyright (c) 2010-2023 Contributors to the openHAB project
+ *
+ * See the NOTICE file(s) distributed with this work for additional
+ * information.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License 2.0 which is available at
+ * http://www.eclipse.org/legal/epl-2.0
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ */
+package org.openhab.binding.sleepiq.internal.api.impl.typeadapters;
+
+import java.time.LocalDate;
+
+import org.eclipse.jdt.annotation.NonNullByDefault;
+
+/**
+ * Type adapter for jsr310 {@link LocalDate} class.
+ *
+ * @author Christophe Bornet - Initial contribution
+ */
+@NonNullByDefault
+public class LocalDateTypeAdapter extends TemporalTypeAdapter<LocalDate> {
+
+    public LocalDateTypeAdapter() {
+        super(LocalDate::parse);
+    }
+}