Simplify DateTimeType handling for WiZ

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
Jacob Laursen 2024-12-17 21:36:30 +01:00 committed by lsiepel
parent 328e91a7fc
commit 9d72871018
2 changed files with 4 additions and 13 deletions

View File

@ -18,7 +18,6 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.wiz.internal.handler.WizHandler; import org.openhab.binding.wiz.internal.handler.WizHandler;
import org.openhab.binding.wiz.internal.handler.WizMediator; import org.openhab.binding.wiz.internal.handler.WizMediator;
import org.openhab.core.i18n.TimeZoneProvider;
import org.openhab.core.thing.Thing; import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingTypeUID; import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.thing.binding.BaseThingHandlerFactory; import org.openhab.core.thing.binding.BaseThingHandlerFactory;
@ -43,15 +42,12 @@ public class WizHandlerFactory extends BaseThingHandlerFactory {
private final WizMediator mediator; private final WizMediator mediator;
private final WizStateDescriptionProvider stateDescriptionProvider; private final WizStateDescriptionProvider stateDescriptionProvider;
private final TimeZoneProvider timeZoneProvider;
@Activate @Activate
public WizHandlerFactory(@Reference WizMediator mediator, public WizHandlerFactory(@Reference WizMediator mediator,
@Reference WizStateDescriptionProvider stateDescriptionProvider, @Reference WizStateDescriptionProvider stateDescriptionProvider) {
@Reference TimeZoneProvider timeZoneProvider) {
this.mediator = mediator; this.mediator = mediator;
this.stateDescriptionProvider = stateDescriptionProvider; this.stateDescriptionProvider = stateDescriptionProvider;
this.timeZoneProvider = timeZoneProvider;
} }
@Override @Override
@ -66,7 +62,7 @@ public class WizHandlerFactory extends BaseThingHandlerFactory {
if (supportsThingType(thing.getThingTypeUID())) { if (supportsThingType(thing.getThingTypeUID())) {
WizHandler handler; WizHandler handler;
handler = new WizHandler(thing, mediator, stateDescriptionProvider, timeZoneProvider); handler = new WizHandler(thing, mediator, stateDescriptionProvider);
mediator.registerThingAndWizBulbHandler(thing, handler); mediator.registerThingAndWizBulbHandler(thing, handler);
return handler; return handler;

View File

@ -21,7 +21,6 @@ import java.net.DatagramPacket;
import java.net.DatagramSocket; import java.net.DatagramSocket;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.SocketTimeoutException; import java.net.SocketTimeoutException;
import java.time.ZonedDateTime;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -55,7 +54,6 @@ import org.openhab.binding.wiz.internal.enums.WizMethodType;
import org.openhab.binding.wiz.internal.utils.ValidationUtils; import org.openhab.binding.wiz.internal.utils.ValidationUtils;
import org.openhab.binding.wiz.internal.utils.WizPacketConverter; import org.openhab.binding.wiz.internal.utils.WizPacketConverter;
import org.openhab.core.config.core.Configuration; import org.openhab.core.config.core.Configuration;
import org.openhab.core.i18n.TimeZoneProvider;
import org.openhab.core.library.types.DateTimeType; import org.openhab.core.library.types.DateTimeType;
import org.openhab.core.library.types.DecimalType; import org.openhab.core.library.types.DecimalType;
import org.openhab.core.library.types.HSBType; import org.openhab.core.library.types.HSBType;
@ -100,7 +98,6 @@ public class WizHandler extends BaseThingHandler {
private final WizPacketConverter converter = new WizPacketConverter(); private final WizPacketConverter converter = new WizPacketConverter();
private final WizStateDescriptionProvider stateDescriptionProvider; private final WizStateDescriptionProvider stateDescriptionProvider;
private final TimeZoneProvider timeZoneProvider;
private final ChannelUID colorTempChannelUID; private final ChannelUID colorTempChannelUID;
private @Nullable ScheduledFuture<?> keepAliveJob; private @Nullable ScheduledFuture<?> keepAliveJob;
private long latestUpdate = -1; private long latestUpdate = -1;
@ -121,7 +118,7 @@ public class WizHandler extends BaseThingHandler {
* @param stateDescriptionProvider A state description provider * @param stateDescriptionProvider A state description provider
*/ */
public WizHandler(final Thing thing, final WizMediator mediator, public WizHandler(final Thing thing, final WizMediator mediator,
WizStateDescriptionProvider stateDescriptionProvider, TimeZoneProvider timeZoneProvider) { WizStateDescriptionProvider stateDescriptionProvider) {
super(thing); super(thing);
try { try {
registrationRequestParam = mediator.getRegistrationParams(); registrationRequestParam = mediator.getRegistrationParams();
@ -129,7 +126,6 @@ public class WizHandler extends BaseThingHandler {
registrationRequestParam = null; registrationRequestParam = null;
} }
this.stateDescriptionProvider = stateDescriptionProvider; this.stateDescriptionProvider = stateDescriptionProvider;
this.timeZoneProvider = timeZoneProvider;
this.mostRecentState = new WizSyncState(); this.mostRecentState = new WizSyncState();
this.isFan = thing.getThingTypeUID().equals(THING_TYPE_FAN) this.isFan = thing.getThingTypeUID().equals(THING_TYPE_FAN)
|| thing.getThingTypeUID().equals(THING_TYPE_FAN_WITH_DIMMABLE_BULB); || thing.getThingTypeUID().equals(THING_TYPE_FAN_WITH_DIMMABLE_BULB);
@ -738,8 +734,7 @@ public class WizHandler extends BaseThingHandler {
updateStatus(ThingStatus.ONLINE); updateStatus(ThingStatus.ONLINE);
latestUpdate = System.currentTimeMillis(); latestUpdate = System.currentTimeMillis();
latestOfflineRefresh = System.currentTimeMillis(); latestOfflineRefresh = System.currentTimeMillis();
final ZonedDateTime zonedDateTime = ZonedDateTime.now(timeZoneProvider.getTimeZone()); updateDeviceState(CHANNEL_LAST_UPDATE, new DateTimeType());
updateDeviceState(CHANNEL_LAST_UPDATE, new DateTimeType(zonedDateTime));
} }
/** /**