From 86955bc39f701114a8987c5d60a86f01e7dcbe03 Mon Sep 17 00:00:00 2001 From: Jacob Laursen Date: Tue, 19 Nov 2024 20:54:46 +0100 Subject: [PATCH] Simplify DateTimeType handling for Philips Somneo Signed-off-by: Jacob Laursen --- .../org/openhab/binding/somneo/internal/SomneoHandler.java | 5 +++-- .../openhab/binding/somneo/internal/SomneoHttpConnector.java | 4 ++-- .../binding/somneo/internal/model/AlarmSettingsData.java | 3 +-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bundles/org.openhab.binding.somneo/src/main/java/org/openhab/binding/somneo/internal/SomneoHandler.java b/bundles/org.openhab.binding.somneo/src/main/java/org/openhab/binding/somneo/internal/SomneoHandler.java index 5de50b2729f..2bd993f1ec0 100644 --- a/bundles/org.openhab.binding.somneo/src/main/java/org/openhab/binding/somneo/internal/SomneoHandler.java +++ b/bundles/org.openhab.binding.somneo/src/main/java/org/openhab/binding/somneo/internal/SomneoHandler.java @@ -15,6 +15,7 @@ package org.openhab.binding.somneo.internal; import static org.openhab.binding.somneo.internal.SomneoBindingConstants.*; import java.io.EOFException; +import java.time.ZoneId; import java.util.Map; import java.util.Objects; import java.util.concurrent.ExecutionException; @@ -356,8 +357,8 @@ public class SomneoHandler extends BaseThingHandler { } break; case CHANNEL_ALARM_TIME: - if (command instanceof DateTimeType decimal) { - connector.setAlarmTime(alarmPosition, decimal); + if (command instanceof DateTimeType dateTimeCommand) { + connector.setAlarmTime(alarmPosition, dateTimeCommand.getZonedDateTime(ZoneId.systemDefault())); } break; case CHANNEL_ALARM_REPEAT_DAY: diff --git a/bundles/org.openhab.binding.somneo/src/main/java/org/openhab/binding/somneo/internal/SomneoHttpConnector.java b/bundles/org.openhab.binding.somneo/src/main/java/org/openhab/binding/somneo/internal/SomneoHttpConnector.java index 2d7aed9da49..6166fe70751 100644 --- a/bundles/org.openhab.binding.somneo/src/main/java/org/openhab/binding/somneo/internal/SomneoHttpConnector.java +++ b/bundles/org.openhab.binding.somneo/src/main/java/org/openhab/binding/somneo/internal/SomneoHttpConnector.java @@ -17,6 +17,7 @@ import static org.openhab.binding.somneo.internal.SomneoBindingConstants.*; import java.io.UnsupportedEncodingException; import java.nio.charset.StandardCharsets; import java.time.LocalTime; +import java.time.ZonedDateTime; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; @@ -46,7 +47,6 @@ import org.openhab.binding.somneo.internal.model.SunsetData; import org.openhab.binding.somneo.internal.model.TimerData; import org.openhab.binding.somneo.internal.model.WifiData; import org.openhab.core.io.net.http.HttpUtil; -import org.openhab.core.library.types.DateTimeType; import org.openhab.core.library.types.DecimalType; import org.openhab.core.library.types.OnOffType; import org.openhab.core.library.types.PercentType; @@ -373,7 +373,7 @@ public class SomneoHttpConnector { executeUrl("PUT", ALARM_EDIT_ENDPOINT, data); } - public void setAlarmTime(int position, DateTimeType time) + public void setAlarmTime(int position, ZonedDateTime time) throws TimeoutException, InterruptedException, ExecutionException { final AlarmSettingsData data = fetchAlarmSettingsData(position); data.setConfigured(true); diff --git a/bundles/org.openhab.binding.somneo/src/main/java/org/openhab/binding/somneo/internal/model/AlarmSettingsData.java b/bundles/org.openhab.binding.somneo/src/main/java/org/openhab/binding/somneo/internal/model/AlarmSettingsData.java index 2b1c29cbb62..0ec313dbe00 100644 --- a/bundles/org.openhab.binding.somneo/src/main/java/org/openhab/binding/somneo/internal/model/AlarmSettingsData.java +++ b/bundles/org.openhab.binding.somneo/src/main/java/org/openhab/binding/somneo/internal/model/AlarmSettingsData.java @@ -148,8 +148,7 @@ public class AlarmSettingsData { } } - public void setAlarmTime(DateTimeType timeState) { - final ZonedDateTime zonedTime = timeState.getZonedDateTime(); + public void setAlarmTime(ZonedDateTime zonedTime) { final LocalTime time = LocalTime.of(zonedTime.getHour(), zonedTime.getMinute()); if (time == null) { return;