Simplify DateTimeType handling for Philips Somneo

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
Jacob Laursen 2024-11-19 20:54:46 +01:00 committed by lsiepel
parent 512e3b239b
commit 86955bc39f
3 changed files with 6 additions and 6 deletions

View File

@ -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:

View File

@ -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);

View File

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