diff --git a/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/api/dto/clip2/Resource.java b/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/api/dto/clip2/Resource.java index c05594aa8df..9dd9d2af535 100644 --- a/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/api/dto/clip2/Resource.java +++ b/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/api/dto/clip2/Resource.java @@ -17,8 +17,6 @@ import java.math.MathContext; import java.math.RoundingMode; import java.time.Duration; import java.time.Instant; -import java.time.ZoneId; -import java.time.ZonedDateTime; import java.util.List; import java.util.Map; import java.util.Objects; @@ -271,7 +269,7 @@ public class Resource { return new DecimalType((controlIds.getOrDefault(getId(), 0).intValue() * 1000) + event.ordinal()); } - public State getButtonLastUpdatedState(ZoneId zoneId) { + public State getButtonLastUpdatedState() { Button button = this.button; if (button == null) { return UnDefType.NULL; @@ -284,7 +282,7 @@ public class Resource { if (Instant.EPOCH.equals(lastChanged)) { return UnDefType.UNDEF; } - return new DateTimeType(ZonedDateTime.ofInstant(lastChanged, zoneId)); + return new DateTimeType(lastChanged); } public List getChildren() { @@ -388,11 +386,9 @@ public class Resource { return UnDefType.NULL; } - public State getContactLastUpdatedState(ZoneId zoneId) { + public State getContactLastUpdatedState() { ContactReport contactReport = this.contactReport; - return Objects.nonNull(contactReport) - ? new DateTimeType(ZonedDateTime.ofInstant(contactReport.getLastChanged(), zoneId)) - : UnDefType.NULL; + return Objects.nonNull(contactReport) ? new DateTimeType(contactReport.getLastChanged()) : UnDefType.NULL; } public State getContactState() { @@ -506,7 +502,7 @@ public class Resource { return new QuantityType<>(Math.pow(10f, (double) lightLevelReport.getLightLevel() / 10000f) - 1f, Units.LUX); } - public State getLightLevelLastUpdatedState(ZoneId zoneId) { + public State getLightLevelLastUpdatedState() { LightLevel lightLevel = this.light; if (lightLevel == null) { return UnDefType.NULL; @@ -519,7 +515,7 @@ public class Resource { if (Instant.EPOCH.equals(lastChanged)) { return UnDefType.UNDEF; } - return new DateTimeType(ZonedDateTime.ofInstant(lastChanged, zoneId)); + return new DateTimeType(lastChanged); } public @Nullable MetaData getMetaData() { @@ -552,7 +548,7 @@ public class Resource { return OnOffType.from(motionReport.isMotion()); } - public State getMotionLastUpdatedState(ZoneId zoneId) { + public State getMotionLastUpdatedState() { Motion motion = this.motion; if (motion == null) { return UnDefType.NULL; @@ -565,7 +561,7 @@ public class Resource { if (Instant.EPOCH.equals(lastChanged)) { return UnDefType.UNDEF; } - return new DateTimeType(ZonedDateTime.ofInstant(lastChanged, zoneId)); + return new DateTimeType(lastChanged); } public State getMotionValidState() { @@ -644,7 +640,7 @@ public class Resource { return rotation.getStepsState(); } - public State getRotaryStepsLastUpdatedState(ZoneId zoneId) { + public State getRotaryStepsLastUpdatedState() { RelativeRotary relativeRotary = this.relativeRotary; if (relativeRotary == null) { return UnDefType.NULL; @@ -657,7 +653,7 @@ public class Resource { if (Instant.EPOCH.equals(lastChanged)) { return UnDefType.UNDEF; } - return new DateTimeType(ZonedDateTime.ofInstant(lastChanged, zoneId)); + return new DateTimeType(lastChanged); } /** @@ -738,10 +734,9 @@ public class Resource { return new JsonObject(); } - public State getTamperLastUpdatedState(ZoneId zoneId) { + public State getTamperLastUpdatedState() { TamperReport report = getTamperReportsLatest(); - return Objects.nonNull(report) ? new DateTimeType(ZonedDateTime.ofInstant(report.getLastChanged(), zoneId)) - : UnDefType.NULL; + return Objects.nonNull(report) ? new DateTimeType(report.getLastChanged()) : UnDefType.NULL; } /** @@ -781,7 +776,7 @@ public class Resource { return new QuantityType<>(temperatureReport.getTemperature(), SIUnits.CELSIUS); } - public State getTemperatureLastUpdatedState(ZoneId zoneId) { + public State getTemperatureLastUpdatedState() { Temperature temperature = this.temperature; if (temperature == null) { return UnDefType.NULL; @@ -794,7 +789,7 @@ public class Resource { if (Instant.EPOCH.equals(lastChanged)) { return UnDefType.UNDEF; } - return new DateTimeType(ZonedDateTime.ofInstant(lastChanged, zoneId)); + return new DateTimeType(lastChanged); } public State getTemperatureValidState() { diff --git a/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/factory/HueThingHandlerFactory.java b/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/factory/HueThingHandlerFactory.java index d12a446f0bf..c86157c1883 100644 --- a/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/factory/HueThingHandlerFactory.java +++ b/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/factory/HueThingHandlerFactory.java @@ -37,7 +37,6 @@ import org.openhab.binding.hue.internal.handler.sensors.TapSwitchHandler; import org.openhab.binding.hue.internal.handler.sensors.TemperatureHandler; import org.openhab.core.config.core.Configuration; import org.openhab.core.i18n.LocaleProvider; -import org.openhab.core.i18n.TimeZoneProvider; import org.openhab.core.i18n.TranslationProvider; import org.openhab.core.io.net.http.HttpClientFactory; import org.openhab.core.thing.Bridge; @@ -83,7 +82,6 @@ public class HueThingHandlerFactory extends BaseThingHandlerFactory { private final Clip2StateDescriptionProvider clip2StateDescriptionProvider; private final TranslationProvider i18nProvider; private final LocaleProvider localeProvider; - private final TimeZoneProvider timeZoneProvider; private final ThingRegistry thingRegistry; private final ItemChannelLinkRegistry itemChannelLinkRegistry; @@ -92,14 +90,13 @@ public class HueThingHandlerFactory extends BaseThingHandlerFactory { final @Reference HueStateDescriptionProvider stateDescriptionProvider, final @Reference Clip2StateDescriptionProvider clip2StateDescriptionProvider, final @Reference TranslationProvider i18nProvider, final @Reference LocaleProvider localeProvider, - final @Reference TimeZoneProvider timeZoneProvider, final @Reference ThingRegistry thingRegistry, + final @Reference ThingRegistry thingRegistry, final @Reference ItemChannelLinkRegistry itemChannelLinkRegistry) { this.httpClientFactory = httpClientFactory; this.stateDescriptionProvider = stateDescriptionProvider; this.clip2StateDescriptionProvider = clip2StateDescriptionProvider; this.i18nProvider = i18nProvider; this.localeProvider = localeProvider; - this.timeZoneProvider = timeZoneProvider; this.thingRegistry = thingRegistry; this.itemChannelLinkRegistry = itemChannelLinkRegistry; } @@ -187,8 +184,7 @@ public class HueThingHandlerFactory extends BaseThingHandlerFactory { return new Clip2BridgeHandler((Bridge) thing, httpClientFactory, thingRegistry, localeProvider, i18nProvider); } else if (Clip2ThingHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) { - return new Clip2ThingHandler(thing, clip2StateDescriptionProvider, timeZoneProvider, thingRegistry, - itemChannelLinkRegistry); + return new Clip2ThingHandler(thing, clip2StateDescriptionProvider, thingRegistry, itemChannelLinkRegistry); } else if (HueBridgeHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) { return new HueBridgeHandler((Bridge) thing, httpClientFactory.getCommonHttpClient(), stateDescriptionProvider); diff --git a/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/handler/Clip2ThingHandler.java b/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/handler/Clip2ThingHandler.java index 285bf635a06..26bbececcf1 100644 --- a/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/handler/Clip2ThingHandler.java +++ b/bundles/org.openhab.binding.hue/src/main/java/org/openhab/binding/hue/internal/handler/Clip2ThingHandler.java @@ -61,7 +61,6 @@ import org.openhab.binding.hue.internal.api.dto.clip2.helper.Setters; import org.openhab.binding.hue.internal.config.Clip2ThingConfig; import org.openhab.binding.hue.internal.exceptions.ApiException; import org.openhab.binding.hue.internal.exceptions.AssetNotLoadedException; -import org.openhab.core.i18n.TimeZoneProvider; import org.openhab.core.library.types.DateTimeType; import org.openhab.core.library.types.DecimalType; import org.openhab.core.library.types.HSBType; @@ -175,7 +174,6 @@ public class Clip2ThingHandler extends BaseThingHandler { private final ThingRegistry thingRegistry; private final ItemChannelLinkRegistry itemChannelLinkRegistry; private final Clip2StateDescriptionProvider stateDescriptionProvider; - private final TimeZoneProvider timeZoneProvider; private String resourceId = "?"; private Resource thisResource; @@ -197,8 +195,7 @@ public class Clip2ThingHandler extends BaseThingHandler { private @Nullable Future updateServiceContributorsTask; public Clip2ThingHandler(Thing thing, Clip2StateDescriptionProvider stateDescriptionProvider, - TimeZoneProvider timeZoneProvider, ThingRegistry thingRegistry, - ItemChannelLinkRegistry itemChannelLinkRegistry) { + ThingRegistry thingRegistry, ItemChannelLinkRegistry itemChannelLinkRegistry) { super(thing); ThingTypeUID thingTypeUID = thing.getThingTypeUID(); @@ -215,7 +212,6 @@ public class Clip2ThingHandler extends BaseThingHandler { this.thingRegistry = thingRegistry; this.itemChannelLinkRegistry = itemChannelLinkRegistry; this.stateDescriptionProvider = stateDescriptionProvider; - this.timeZoneProvider = timeZoneProvider; } /** @@ -926,7 +922,7 @@ public class Clip2ThingHandler extends BaseThingHandler { updateState(CHANNEL_2_BUTTON_LAST_EVENT, buttonState, fullUpdate); } // Update channel from timestamp if last button pressed. - State buttonLastUpdatedState = resource.getButtonLastUpdatedState(timeZoneProvider.getTimeZone()); + State buttonLastUpdatedState = resource.getButtonLastUpdatedState(); if (buttonLastUpdatedState instanceof DateTimeType) { Instant buttonLastUpdatedInstant = ((DateTimeType) buttonLastUpdatedState).getInstant(); if (buttonLastUpdatedInstant.isAfter(buttonGroupLastUpdated)) { @@ -968,16 +964,14 @@ public class Clip2ThingHandler extends BaseThingHandler { case LIGHT_LEVEL: updateState(CHANNEL_2_LIGHT_LEVEL, resource.getLightLevelState(), fullUpdate); - updateState(CHANNEL_2_LIGHT_LEVEL_LAST_UPDATED, - resource.getLightLevelLastUpdatedState(timeZoneProvider.getTimeZone()), fullUpdate); + updateState(CHANNEL_2_LIGHT_LEVEL_LAST_UPDATED, resource.getLightLevelLastUpdatedState(), fullUpdate); updateState(CHANNEL_2_LIGHT_LEVEL_ENABLED, resource.getEnabledState(), fullUpdate); break; case MOTION: case CAMERA_MOTION: updateState(CHANNEL_2_MOTION, resource.getMotionState(), fullUpdate); - updateState(CHANNEL_2_MOTION_LAST_UPDATED, - resource.getMotionLastUpdatedState(timeZoneProvider.getTimeZone()), fullUpdate); + updateState(CHANNEL_2_MOTION_LAST_UPDATED, resource.getMotionLastUpdatedState(), fullUpdate); updateState(CHANNEL_2_MOTION_ENABLED, resource.getEnabledState(), fullUpdate); break; @@ -988,14 +982,12 @@ public class Clip2ThingHandler extends BaseThingHandler { } else { updateState(CHANNEL_2_ROTARY_STEPS, resource.getRotaryStepsState(), fullUpdate); } - updateState(CHANNEL_2_ROTARY_STEPS_LAST_UPDATED, - resource.getRotaryStepsLastUpdatedState(timeZoneProvider.getTimeZone()), fullUpdate); + updateState(CHANNEL_2_ROTARY_STEPS_LAST_UPDATED, resource.getRotaryStepsLastUpdatedState(), fullUpdate); break; case TEMPERATURE: updateState(CHANNEL_2_TEMPERATURE, resource.getTemperatureState(), fullUpdate); - updateState(CHANNEL_2_TEMPERATURE_LAST_UPDATED, - resource.getTemperatureLastUpdatedState(timeZoneProvider.getTimeZone()), fullUpdate); + updateState(CHANNEL_2_TEMPERATURE_LAST_UPDATED, resource.getTemperatureLastUpdatedState(), fullUpdate); updateState(CHANNEL_2_TEMPERATURE_ENABLED, resource.getEnabledState(), fullUpdate); break; @@ -1009,15 +1001,13 @@ public class Clip2ThingHandler extends BaseThingHandler { case CONTACT: updateState(CHANNEL_2_SECURITY_CONTACT, resource.getContactState(), fullUpdate); - updateState(CHANNEL_2_SECURITY_CONTACT_LAST_UPDATED, - resource.getContactLastUpdatedState(timeZoneProvider.getTimeZone()), fullUpdate); + updateState(CHANNEL_2_SECURITY_CONTACT_LAST_UPDATED, resource.getContactLastUpdatedState(), fullUpdate); updateState(CHANNEL_2_SECURITY_CONTACT_ENABLED, resource.getEnabledState(), fullUpdate); break; case TAMPER: updateState(CHANNEL_2_SECURITY_TAMPER, resource.getTamperState(), fullUpdate); - updateState(CHANNEL_2_SECURITY_TAMPER_LAST_UPDATED, - resource.getTamperLastUpdatedState(timeZoneProvider.getTimeZone()), fullUpdate); + updateState(CHANNEL_2_SECURITY_TAMPER_LAST_UPDATED, resource.getTamperLastUpdatedState(), fullUpdate); break; case SMART_SCENE: diff --git a/bundles/org.openhab.binding.hue/src/test/java/org/openhab/binding/hue/internal/clip2/Clip2DtoTest.java b/bundles/org.openhab.binding.hue/src/test/java/org/openhab/binding/hue/internal/clip2/Clip2DtoTest.java index 6104c6fbe10..7368a19d56a 100644 --- a/bundles/org.openhab.binding.hue/src/test/java/org/openhab/binding/hue/internal/clip2/Clip2DtoTest.java +++ b/bundles/org.openhab.binding.hue/src/test/java/org/openhab/binding/hue/internal/clip2/Clip2DtoTest.java @@ -20,7 +20,6 @@ import java.io.IOException; import java.lang.reflect.Field; import java.time.Duration; import java.time.Instant; -import java.time.ZoneId; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -124,8 +123,7 @@ class Clip2DtoTest { assertNotNull(button); assertEquals(new DecimalType(2003), item.getButtonEventState(Map.of("00000000-0000-0000-0000-000000000001", 2))); - assertEquals(new DateTimeType("2023-09-17T18:51:36.959+0000"), - item.getButtonLastUpdatedState(ZoneId.of("UTC"))); + assertEquals(new DateTimeType("2023-09-17T18:51:36.959+0000"), item.getButtonLastUpdatedState()); } @Test @@ -346,8 +344,7 @@ class Clip2DtoTest { assertNotNull(enabled); assertTrue(enabled); assertEquals(QuantityType.valueOf("1.2792921774337476 lx"), item.getLightLevelState()); - assertEquals(new DateTimeType("2023-09-11T19:20:02.958+0000"), - item.getLightLevelLastUpdatedState(ZoneId.of("UTC"))); + assertEquals(new DateTimeType("2023-09-11T19:20:02.958+0000"), item.getLightLevelLastUpdatedState()); } @Test @@ -540,8 +537,7 @@ class Clip2DtoTest { assertNotNull(enabled); assertTrue(enabled); assertEquals(OnOffType.ON, item.getMotionState()); - assertEquals(new DateTimeType("2023-09-04T20:04:30.395+0000"), - item.getMotionLastUpdatedState(ZoneId.of("UTC"))); + assertEquals(new DateTimeType("2023-09-04T20:04:30.395+0000"), item.getMotionLastUpdatedState()); } @Test @@ -631,8 +627,7 @@ class Clip2DtoTest { assertNotNull(enabled); assertTrue(enabled); assertEquals(QuantityType.valueOf("23.34 °C"), item.getTemperatureState()); - assertEquals(new DateTimeType("2023-09-06T18:22:07.016+0000"), - item.getTemperatureLastUpdatedState(ZoneId.of("UTC"))); + assertEquals(new DateTimeType("2023-09-06T18:22:07.016+0000"), item.getTemperatureLastUpdatedState()); } @Test @@ -721,12 +716,11 @@ class Clip2DtoTest { assertEquals(ResourceType.CONTACT, resource.getType()); assertEquals(OpenClosedType.CLOSED, resource.getContactState()); - assertEquals(new DateTimeType("2023-10-10T19:10:55.919Z"), - resource.getContactLastUpdatedState(ZoneId.of("UTC"))); + assertEquals(new DateTimeType("2023-10-10T19:10:55.919Z"), resource.getContactLastUpdatedState()); resource.setContactReport(new ContactReport().setLastChanged(Instant.now()).setContactState("no_contact")); assertEquals(OpenClosedType.OPEN, resource.getContactState()); - assertTrue(resource.getContactLastUpdatedState(ZoneId.of("UTC")) instanceof DateTimeType); + assertTrue(resource.getContactLastUpdatedState() instanceof DateTimeType); } @Test @@ -741,8 +735,7 @@ class Clip2DtoTest { assertEquals(ResourceType.TAMPER, resource.getType()); assertEquals(OpenClosedType.CLOSED, resource.getTamperState()); - assertEquals(new DateTimeType("2023-01-01T00:00:00.001Z"), - resource.getTamperLastUpdatedState(ZoneId.of("UTC"))); + assertEquals(new DateTimeType("2023-01-01T00:00:00.001Z"), resource.getTamperLastUpdatedState()); Instant start = Instant.now(); List tamperReports; @@ -752,7 +745,7 @@ class Clip2DtoTest { tamperReports.add(new TamperReport().setTamperState("not_tampered").setLastChanged(start)); resource.setTamperReports(tamperReports); assertEquals(OpenClosedType.CLOSED, resource.getTamperState()); - state = resource.getTamperLastUpdatedState(ZoneId.of("UTC")); + state = resource.getTamperLastUpdatedState(); assertTrue(state instanceof DateTimeType); assertEquals(start, ((DateTimeType) state).getInstant()); @@ -761,7 +754,7 @@ class Clip2DtoTest { tamperReports.add(new TamperReport().setTamperState("tampered").setLastChanged(start.plusSeconds(1))); resource.setTamperReports(tamperReports); assertEquals(OpenClosedType.OPEN, resource.getTamperState()); - state = resource.getTamperLastUpdatedState(ZoneId.of("UTC")); + state = resource.getTamperLastUpdatedState(); assertTrue(state instanceof DateTimeType); assertEquals(start.plusSeconds(1), ((DateTimeType) state).getInstant()); @@ -771,7 +764,7 @@ class Clip2DtoTest { tamperReports.add(new TamperReport().setTamperState("not_tampered").setLastChanged(start.plusSeconds(2))); resource.setTamperReports(tamperReports); assertEquals(OpenClosedType.CLOSED, resource.getTamperState()); - state = resource.getTamperLastUpdatedState(ZoneId.of("UTC")); + state = resource.getTamperLastUpdatedState(); assertTrue(state instanceof DateTimeType); assertEquals(start.plusSeconds(2), ((DateTimeType) state).getInstant()); } @@ -791,8 +784,7 @@ class Clip2DtoTest { assertNotNull(enabled); assertTrue(enabled); assertEquals(OnOffType.ON, resource.getMotionState()); - assertEquals(new DateTimeType("2020-04-01T20:04:30.395Z"), - resource.getMotionLastUpdatedState(ZoneId.of("UTC"))); + assertEquals(new DateTimeType("2020-04-01T20:04:30.395Z"), resource.getMotionLastUpdatedState()); } void testFixedEffectSetter() { @@ -929,6 +921,6 @@ class Clip2DtoTest { assertNotNull(enabled); assertTrue(enabled); assertEquals(OnOffType.ON, item.getMotionState()); - assertEquals(new DateTimeType("2024-12-13T11:01:25.156Z"), item.getMotionLastUpdatedState(ZoneId.of("UTC"))); + assertEquals(new DateTimeType("2024-12-13T11:01:25.156Z"), item.getMotionLastUpdatedState()); } }