Simplify DateTimeType handling for Hydrawise

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
Jacob Laursen 2024-11-17 18:18:35 +01:00 committed by lsiepel
parent 28b6624644
commit fb7ba1feb1

View File

@ -16,6 +16,7 @@ import static org.openhab.binding.hydrawise.internal.HydrawiseBindingConstants.*
import java.time.Instant; import java.time.Instant;
import java.time.OffsetDateTime; import java.time.OffsetDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset; import java.time.ZoneOffset;
import java.time.ZonedDateTime; import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
@ -211,20 +212,20 @@ public class HydrawiseControllerHandler extends BaseThingHandler implements Hydr
} }
break; break;
case CHANNEL_ZONE_SUSPENDUNTIL: case CHANNEL_ZONE_SUSPENDUNTIL:
if (!(command instanceof DateTimeType)) { if (!(command instanceof DateTimeType dateTimeCommand)) {
logger.warn("Invalid command type for suspend {}", command.getClass().getName()); logger.warn("Invalid command type for suspend {}", command.getClass().getName());
return; return;
} }
if (allCommand) { if (allCommand) {
client.suspendAllRelays(controllerId, client.suspendAllRelays(controllerId,
((DateTimeType) command).getZonedDateTime().format(DATE_FORMATTER)); dateTimeCommand.getZonedDateTime(ZoneId.systemDefault()).format(DATE_FORMATTER));
} else if (zone != null) { } else if (zone != null) {
client.suspendRelay(zone.id, client.suspendRelay(zone.id,
((DateTimeType) command).getZonedDateTime().format(DATE_FORMATTER)); dateTimeCommand.getZonedDateTime(ZoneId.systemDefault()).format(DATE_FORMATTER));
} }
break; break;
default: default:
logger.warn("Uknown channelId {}", channelId); logger.warn("Unknown channelId {}", channelId);
return; return;
} }
HydrawiseAccountHandler handler = getAccountHandler(); HydrawiseAccountHandler handler = getAccountHandler();