Simplify DateTimeType handling for Philips Hue

Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
Jacob Laursen 2024-11-27 23:44:41 +01:00 committed by lsiepel
parent 7fd9fc8554
commit 28b6624644
4 changed files with 36 additions and 63 deletions

View File

@ -17,8 +17,6 @@ import java.math.MathContext;
import java.math.RoundingMode; import java.math.RoundingMode;
import java.time.Duration; import java.time.Duration;
import java.time.Instant; import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
@ -271,7 +269,7 @@ public class Resource {
return new DecimalType((controlIds.getOrDefault(getId(), 0).intValue() * 1000) + event.ordinal()); return new DecimalType((controlIds.getOrDefault(getId(), 0).intValue() * 1000) + event.ordinal());
} }
public State getButtonLastUpdatedState(ZoneId zoneId) { public State getButtonLastUpdatedState() {
Button button = this.button; Button button = this.button;
if (button == null) { if (button == null) {
return UnDefType.NULL; return UnDefType.NULL;
@ -284,7 +282,7 @@ public class Resource {
if (Instant.EPOCH.equals(lastChanged)) { if (Instant.EPOCH.equals(lastChanged)) {
return UnDefType.UNDEF; return UnDefType.UNDEF;
} }
return new DateTimeType(ZonedDateTime.ofInstant(lastChanged, zoneId)); return new DateTimeType(lastChanged);
} }
public List<ResourceReference> getChildren() { public List<ResourceReference> getChildren() {
@ -388,11 +386,9 @@ public class Resource {
return UnDefType.NULL; return UnDefType.NULL;
} }
public State getContactLastUpdatedState(ZoneId zoneId) { public State getContactLastUpdatedState() {
ContactReport contactReport = this.contactReport; ContactReport contactReport = this.contactReport;
return Objects.nonNull(contactReport) return Objects.nonNull(contactReport) ? new DateTimeType(contactReport.getLastChanged()) : UnDefType.NULL;
? new DateTimeType(ZonedDateTime.ofInstant(contactReport.getLastChanged(), zoneId))
: UnDefType.NULL;
} }
public State getContactState() { public State getContactState() {
@ -506,7 +502,7 @@ public class Resource {
return new QuantityType<>(Math.pow(10f, (double) lightLevelReport.getLightLevel() / 10000f) - 1f, Units.LUX); 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; LightLevel lightLevel = this.light;
if (lightLevel == null) { if (lightLevel == null) {
return UnDefType.NULL; return UnDefType.NULL;
@ -519,7 +515,7 @@ public class Resource {
if (Instant.EPOCH.equals(lastChanged)) { if (Instant.EPOCH.equals(lastChanged)) {
return UnDefType.UNDEF; return UnDefType.UNDEF;
} }
return new DateTimeType(ZonedDateTime.ofInstant(lastChanged, zoneId)); return new DateTimeType(lastChanged);
} }
public @Nullable MetaData getMetaData() { public @Nullable MetaData getMetaData() {
@ -552,7 +548,7 @@ public class Resource {
return OnOffType.from(motionReport.isMotion()); return OnOffType.from(motionReport.isMotion());
} }
public State getMotionLastUpdatedState(ZoneId zoneId) { public State getMotionLastUpdatedState() {
Motion motion = this.motion; Motion motion = this.motion;
if (motion == null) { if (motion == null) {
return UnDefType.NULL; return UnDefType.NULL;
@ -565,7 +561,7 @@ public class Resource {
if (Instant.EPOCH.equals(lastChanged)) { if (Instant.EPOCH.equals(lastChanged)) {
return UnDefType.UNDEF; return UnDefType.UNDEF;
} }
return new DateTimeType(ZonedDateTime.ofInstant(lastChanged, zoneId)); return new DateTimeType(lastChanged);
} }
public State getMotionValidState() { public State getMotionValidState() {
@ -644,7 +640,7 @@ public class Resource {
return rotation.getStepsState(); return rotation.getStepsState();
} }
public State getRotaryStepsLastUpdatedState(ZoneId zoneId) { public State getRotaryStepsLastUpdatedState() {
RelativeRotary relativeRotary = this.relativeRotary; RelativeRotary relativeRotary = this.relativeRotary;
if (relativeRotary == null) { if (relativeRotary == null) {
return UnDefType.NULL; return UnDefType.NULL;
@ -657,7 +653,7 @@ public class Resource {
if (Instant.EPOCH.equals(lastChanged)) { if (Instant.EPOCH.equals(lastChanged)) {
return UnDefType.UNDEF; return UnDefType.UNDEF;
} }
return new DateTimeType(ZonedDateTime.ofInstant(lastChanged, zoneId)); return new DateTimeType(lastChanged);
} }
/** /**
@ -738,10 +734,9 @@ public class Resource {
return new JsonObject(); return new JsonObject();
} }
public State getTamperLastUpdatedState(ZoneId zoneId) { public State getTamperLastUpdatedState() {
TamperReport report = getTamperReportsLatest(); TamperReport report = getTamperReportsLatest();
return Objects.nonNull(report) ? new DateTimeType(ZonedDateTime.ofInstant(report.getLastChanged(), zoneId)) return Objects.nonNull(report) ? new DateTimeType(report.getLastChanged()) : UnDefType.NULL;
: UnDefType.NULL;
} }
/** /**
@ -781,7 +776,7 @@ public class Resource {
return new QuantityType<>(temperatureReport.getTemperature(), SIUnits.CELSIUS); return new QuantityType<>(temperatureReport.getTemperature(), SIUnits.CELSIUS);
} }
public State getTemperatureLastUpdatedState(ZoneId zoneId) { public State getTemperatureLastUpdatedState() {
Temperature temperature = this.temperature; Temperature temperature = this.temperature;
if (temperature == null) { if (temperature == null) {
return UnDefType.NULL; return UnDefType.NULL;
@ -794,7 +789,7 @@ public class Resource {
if (Instant.EPOCH.equals(lastChanged)) { if (Instant.EPOCH.equals(lastChanged)) {
return UnDefType.UNDEF; return UnDefType.UNDEF;
} }
return new DateTimeType(ZonedDateTime.ofInstant(lastChanged, zoneId)); return new DateTimeType(lastChanged);
} }
public State getTemperatureValidState() { public State getTemperatureValidState() {

View File

@ -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.binding.hue.internal.handler.sensors.TemperatureHandler;
import org.openhab.core.config.core.Configuration; import org.openhab.core.config.core.Configuration;
import org.openhab.core.i18n.LocaleProvider; import org.openhab.core.i18n.LocaleProvider;
import org.openhab.core.i18n.TimeZoneProvider;
import org.openhab.core.i18n.TranslationProvider; import org.openhab.core.i18n.TranslationProvider;
import org.openhab.core.io.net.http.HttpClientFactory; import org.openhab.core.io.net.http.HttpClientFactory;
import org.openhab.core.thing.Bridge; import org.openhab.core.thing.Bridge;
@ -83,7 +82,6 @@ public class HueThingHandlerFactory extends BaseThingHandlerFactory {
private final Clip2StateDescriptionProvider clip2StateDescriptionProvider; private final Clip2StateDescriptionProvider clip2StateDescriptionProvider;
private final TranslationProvider i18nProvider; private final TranslationProvider i18nProvider;
private final LocaleProvider localeProvider; private final LocaleProvider localeProvider;
private final TimeZoneProvider timeZoneProvider;
private final ThingRegistry thingRegistry; private final ThingRegistry thingRegistry;
private final ItemChannelLinkRegistry itemChannelLinkRegistry; private final ItemChannelLinkRegistry itemChannelLinkRegistry;
@ -92,14 +90,13 @@ public class HueThingHandlerFactory extends BaseThingHandlerFactory {
final @Reference HueStateDescriptionProvider stateDescriptionProvider, final @Reference HueStateDescriptionProvider stateDescriptionProvider,
final @Reference Clip2StateDescriptionProvider clip2StateDescriptionProvider, final @Reference Clip2StateDescriptionProvider clip2StateDescriptionProvider,
final @Reference TranslationProvider i18nProvider, final @Reference LocaleProvider localeProvider, final @Reference TranslationProvider i18nProvider, final @Reference LocaleProvider localeProvider,
final @Reference TimeZoneProvider timeZoneProvider, final @Reference ThingRegistry thingRegistry, final @Reference ThingRegistry thingRegistry,
final @Reference ItemChannelLinkRegistry itemChannelLinkRegistry) { final @Reference ItemChannelLinkRegistry itemChannelLinkRegistry) {
this.httpClientFactory = httpClientFactory; this.httpClientFactory = httpClientFactory;
this.stateDescriptionProvider = stateDescriptionProvider; this.stateDescriptionProvider = stateDescriptionProvider;
this.clip2StateDescriptionProvider = clip2StateDescriptionProvider; this.clip2StateDescriptionProvider = clip2StateDescriptionProvider;
this.i18nProvider = i18nProvider; this.i18nProvider = i18nProvider;
this.localeProvider = localeProvider; this.localeProvider = localeProvider;
this.timeZoneProvider = timeZoneProvider;
this.thingRegistry = thingRegistry; this.thingRegistry = thingRegistry;
this.itemChannelLinkRegistry = itemChannelLinkRegistry; this.itemChannelLinkRegistry = itemChannelLinkRegistry;
} }
@ -187,8 +184,7 @@ public class HueThingHandlerFactory extends BaseThingHandlerFactory {
return new Clip2BridgeHandler((Bridge) thing, httpClientFactory, thingRegistry, localeProvider, return new Clip2BridgeHandler((Bridge) thing, httpClientFactory, thingRegistry, localeProvider,
i18nProvider); i18nProvider);
} else if (Clip2ThingHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) { } else if (Clip2ThingHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
return new Clip2ThingHandler(thing, clip2StateDescriptionProvider, timeZoneProvider, thingRegistry, return new Clip2ThingHandler(thing, clip2StateDescriptionProvider, thingRegistry, itemChannelLinkRegistry);
itemChannelLinkRegistry);
} else if (HueBridgeHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) { } else if (HueBridgeHandler.SUPPORTED_THING_TYPES.contains(thingTypeUID)) {
return new HueBridgeHandler((Bridge) thing, httpClientFactory.getCommonHttpClient(), return new HueBridgeHandler((Bridge) thing, httpClientFactory.getCommonHttpClient(),
stateDescriptionProvider); stateDescriptionProvider);

View File

@ -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.config.Clip2ThingConfig;
import org.openhab.binding.hue.internal.exceptions.ApiException; import org.openhab.binding.hue.internal.exceptions.ApiException;
import org.openhab.binding.hue.internal.exceptions.AssetNotLoadedException; 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.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;
@ -175,7 +174,6 @@ public class Clip2ThingHandler extends BaseThingHandler {
private final ThingRegistry thingRegistry; private final ThingRegistry thingRegistry;
private final ItemChannelLinkRegistry itemChannelLinkRegistry; private final ItemChannelLinkRegistry itemChannelLinkRegistry;
private final Clip2StateDescriptionProvider stateDescriptionProvider; private final Clip2StateDescriptionProvider stateDescriptionProvider;
private final TimeZoneProvider timeZoneProvider;
private String resourceId = "?"; private String resourceId = "?";
private Resource thisResource; private Resource thisResource;
@ -197,8 +195,7 @@ public class Clip2ThingHandler extends BaseThingHandler {
private @Nullable Future<?> updateServiceContributorsTask; private @Nullable Future<?> updateServiceContributorsTask;
public Clip2ThingHandler(Thing thing, Clip2StateDescriptionProvider stateDescriptionProvider, public Clip2ThingHandler(Thing thing, Clip2StateDescriptionProvider stateDescriptionProvider,
TimeZoneProvider timeZoneProvider, ThingRegistry thingRegistry, ThingRegistry thingRegistry, ItemChannelLinkRegistry itemChannelLinkRegistry) {
ItemChannelLinkRegistry itemChannelLinkRegistry) {
super(thing); super(thing);
ThingTypeUID thingTypeUID = thing.getThingTypeUID(); ThingTypeUID thingTypeUID = thing.getThingTypeUID();
@ -215,7 +212,6 @@ public class Clip2ThingHandler extends BaseThingHandler {
this.thingRegistry = thingRegistry; this.thingRegistry = thingRegistry;
this.itemChannelLinkRegistry = itemChannelLinkRegistry; this.itemChannelLinkRegistry = itemChannelLinkRegistry;
this.stateDescriptionProvider = stateDescriptionProvider; this.stateDescriptionProvider = stateDescriptionProvider;
this.timeZoneProvider = timeZoneProvider;
} }
/** /**
@ -926,7 +922,7 @@ public class Clip2ThingHandler extends BaseThingHandler {
updateState(CHANNEL_2_BUTTON_LAST_EVENT, buttonState, fullUpdate); updateState(CHANNEL_2_BUTTON_LAST_EVENT, buttonState, fullUpdate);
} }
// Update channel from timestamp if last button pressed. // Update channel from timestamp if last button pressed.
State buttonLastUpdatedState = resource.getButtonLastUpdatedState(timeZoneProvider.getTimeZone()); State buttonLastUpdatedState = resource.getButtonLastUpdatedState();
if (buttonLastUpdatedState instanceof DateTimeType) { if (buttonLastUpdatedState instanceof DateTimeType) {
Instant buttonLastUpdatedInstant = ((DateTimeType) buttonLastUpdatedState).getInstant(); Instant buttonLastUpdatedInstant = ((DateTimeType) buttonLastUpdatedState).getInstant();
if (buttonLastUpdatedInstant.isAfter(buttonGroupLastUpdated)) { if (buttonLastUpdatedInstant.isAfter(buttonGroupLastUpdated)) {
@ -968,16 +964,14 @@ public class Clip2ThingHandler extends BaseThingHandler {
case LIGHT_LEVEL: case LIGHT_LEVEL:
updateState(CHANNEL_2_LIGHT_LEVEL, resource.getLightLevelState(), fullUpdate); updateState(CHANNEL_2_LIGHT_LEVEL, resource.getLightLevelState(), fullUpdate);
updateState(CHANNEL_2_LIGHT_LEVEL_LAST_UPDATED, updateState(CHANNEL_2_LIGHT_LEVEL_LAST_UPDATED, resource.getLightLevelLastUpdatedState(), fullUpdate);
resource.getLightLevelLastUpdatedState(timeZoneProvider.getTimeZone()), fullUpdate);
updateState(CHANNEL_2_LIGHT_LEVEL_ENABLED, resource.getEnabledState(), fullUpdate); updateState(CHANNEL_2_LIGHT_LEVEL_ENABLED, resource.getEnabledState(), fullUpdate);
break; break;
case MOTION: case MOTION:
case CAMERA_MOTION: case CAMERA_MOTION:
updateState(CHANNEL_2_MOTION, resource.getMotionState(), fullUpdate); updateState(CHANNEL_2_MOTION, resource.getMotionState(), fullUpdate);
updateState(CHANNEL_2_MOTION_LAST_UPDATED, updateState(CHANNEL_2_MOTION_LAST_UPDATED, resource.getMotionLastUpdatedState(), fullUpdate);
resource.getMotionLastUpdatedState(timeZoneProvider.getTimeZone()), fullUpdate);
updateState(CHANNEL_2_MOTION_ENABLED, resource.getEnabledState(), fullUpdate); updateState(CHANNEL_2_MOTION_ENABLED, resource.getEnabledState(), fullUpdate);
break; break;
@ -988,14 +982,12 @@ public class Clip2ThingHandler extends BaseThingHandler {
} else { } else {
updateState(CHANNEL_2_ROTARY_STEPS, resource.getRotaryStepsState(), fullUpdate); updateState(CHANNEL_2_ROTARY_STEPS, resource.getRotaryStepsState(), fullUpdate);
} }
updateState(CHANNEL_2_ROTARY_STEPS_LAST_UPDATED, updateState(CHANNEL_2_ROTARY_STEPS_LAST_UPDATED, resource.getRotaryStepsLastUpdatedState(), fullUpdate);
resource.getRotaryStepsLastUpdatedState(timeZoneProvider.getTimeZone()), fullUpdate);
break; break;
case TEMPERATURE: case TEMPERATURE:
updateState(CHANNEL_2_TEMPERATURE, resource.getTemperatureState(), fullUpdate); updateState(CHANNEL_2_TEMPERATURE, resource.getTemperatureState(), fullUpdate);
updateState(CHANNEL_2_TEMPERATURE_LAST_UPDATED, updateState(CHANNEL_2_TEMPERATURE_LAST_UPDATED, resource.getTemperatureLastUpdatedState(), fullUpdate);
resource.getTemperatureLastUpdatedState(timeZoneProvider.getTimeZone()), fullUpdate);
updateState(CHANNEL_2_TEMPERATURE_ENABLED, resource.getEnabledState(), fullUpdate); updateState(CHANNEL_2_TEMPERATURE_ENABLED, resource.getEnabledState(), fullUpdate);
break; break;
@ -1009,15 +1001,13 @@ public class Clip2ThingHandler extends BaseThingHandler {
case CONTACT: case CONTACT:
updateState(CHANNEL_2_SECURITY_CONTACT, resource.getContactState(), fullUpdate); updateState(CHANNEL_2_SECURITY_CONTACT, resource.getContactState(), fullUpdate);
updateState(CHANNEL_2_SECURITY_CONTACT_LAST_UPDATED, updateState(CHANNEL_2_SECURITY_CONTACT_LAST_UPDATED, resource.getContactLastUpdatedState(), fullUpdate);
resource.getContactLastUpdatedState(timeZoneProvider.getTimeZone()), fullUpdate);
updateState(CHANNEL_2_SECURITY_CONTACT_ENABLED, resource.getEnabledState(), fullUpdate); updateState(CHANNEL_2_SECURITY_CONTACT_ENABLED, resource.getEnabledState(), fullUpdate);
break; break;
case TAMPER: case TAMPER:
updateState(CHANNEL_2_SECURITY_TAMPER, resource.getTamperState(), fullUpdate); updateState(CHANNEL_2_SECURITY_TAMPER, resource.getTamperState(), fullUpdate);
updateState(CHANNEL_2_SECURITY_TAMPER_LAST_UPDATED, updateState(CHANNEL_2_SECURITY_TAMPER_LAST_UPDATED, resource.getTamperLastUpdatedState(), fullUpdate);
resource.getTamperLastUpdatedState(timeZoneProvider.getTimeZone()), fullUpdate);
break; break;
case SMART_SCENE: case SMART_SCENE:

View File

@ -20,7 +20,6 @@ import java.io.IOException;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.time.Duration; import java.time.Duration;
import java.time.Instant; import java.time.Instant;
import java.time.ZoneId;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -124,8 +123,7 @@ class Clip2DtoTest {
assertNotNull(button); assertNotNull(button);
assertEquals(new DecimalType(2003), assertEquals(new DecimalType(2003),
item.getButtonEventState(Map.of("00000000-0000-0000-0000-000000000001", 2))); item.getButtonEventState(Map.of("00000000-0000-0000-0000-000000000001", 2)));
assertEquals(new DateTimeType("2023-09-17T18:51:36.959+0000"), assertEquals(new DateTimeType("2023-09-17T18:51:36.959+0000"), item.getButtonLastUpdatedState());
item.getButtonLastUpdatedState(ZoneId.of("UTC")));
} }
@Test @Test
@ -346,8 +344,7 @@ class Clip2DtoTest {
assertNotNull(enabled); assertNotNull(enabled);
assertTrue(enabled); assertTrue(enabled);
assertEquals(QuantityType.valueOf("1.2792921774337476 lx"), item.getLightLevelState()); assertEquals(QuantityType.valueOf("1.2792921774337476 lx"), item.getLightLevelState());
assertEquals(new DateTimeType("2023-09-11T19:20:02.958+0000"), assertEquals(new DateTimeType("2023-09-11T19:20:02.958+0000"), item.getLightLevelLastUpdatedState());
item.getLightLevelLastUpdatedState(ZoneId.of("UTC")));
} }
@Test @Test
@ -540,8 +537,7 @@ class Clip2DtoTest {
assertNotNull(enabled); assertNotNull(enabled);
assertTrue(enabled); assertTrue(enabled);
assertEquals(OnOffType.ON, item.getMotionState()); assertEquals(OnOffType.ON, item.getMotionState());
assertEquals(new DateTimeType("2023-09-04T20:04:30.395+0000"), assertEquals(new DateTimeType("2023-09-04T20:04:30.395+0000"), item.getMotionLastUpdatedState());
item.getMotionLastUpdatedState(ZoneId.of("UTC")));
} }
@Test @Test
@ -631,8 +627,7 @@ class Clip2DtoTest {
assertNotNull(enabled); assertNotNull(enabled);
assertTrue(enabled); assertTrue(enabled);
assertEquals(QuantityType.valueOf("23.34 °C"), item.getTemperatureState()); assertEquals(QuantityType.valueOf("23.34 °C"), item.getTemperatureState());
assertEquals(new DateTimeType("2023-09-06T18:22:07.016+0000"), assertEquals(new DateTimeType("2023-09-06T18:22:07.016+0000"), item.getTemperatureLastUpdatedState());
item.getTemperatureLastUpdatedState(ZoneId.of("UTC")));
} }
@Test @Test
@ -721,12 +716,11 @@ class Clip2DtoTest {
assertEquals(ResourceType.CONTACT, resource.getType()); assertEquals(ResourceType.CONTACT, resource.getType());
assertEquals(OpenClosedType.CLOSED, resource.getContactState()); assertEquals(OpenClosedType.CLOSED, resource.getContactState());
assertEquals(new DateTimeType("2023-10-10T19:10:55.919Z"), assertEquals(new DateTimeType("2023-10-10T19:10:55.919Z"), resource.getContactLastUpdatedState());
resource.getContactLastUpdatedState(ZoneId.of("UTC")));
resource.setContactReport(new ContactReport().setLastChanged(Instant.now()).setContactState("no_contact")); resource.setContactReport(new ContactReport().setLastChanged(Instant.now()).setContactState("no_contact"));
assertEquals(OpenClosedType.OPEN, resource.getContactState()); assertEquals(OpenClosedType.OPEN, resource.getContactState());
assertTrue(resource.getContactLastUpdatedState(ZoneId.of("UTC")) instanceof DateTimeType); assertTrue(resource.getContactLastUpdatedState() instanceof DateTimeType);
} }
@Test @Test
@ -741,8 +735,7 @@ class Clip2DtoTest {
assertEquals(ResourceType.TAMPER, resource.getType()); assertEquals(ResourceType.TAMPER, resource.getType());
assertEquals(OpenClosedType.CLOSED, resource.getTamperState()); assertEquals(OpenClosedType.CLOSED, resource.getTamperState());
assertEquals(new DateTimeType("2023-01-01T00:00:00.001Z"), assertEquals(new DateTimeType("2023-01-01T00:00:00.001Z"), resource.getTamperLastUpdatedState());
resource.getTamperLastUpdatedState(ZoneId.of("UTC")));
Instant start = Instant.now(); Instant start = Instant.now();
List<TamperReport> tamperReports; List<TamperReport> tamperReports;
@ -752,7 +745,7 @@ class Clip2DtoTest {
tamperReports.add(new TamperReport().setTamperState("not_tampered").setLastChanged(start)); tamperReports.add(new TamperReport().setTamperState("not_tampered").setLastChanged(start));
resource.setTamperReports(tamperReports); resource.setTamperReports(tamperReports);
assertEquals(OpenClosedType.CLOSED, resource.getTamperState()); assertEquals(OpenClosedType.CLOSED, resource.getTamperState());
state = resource.getTamperLastUpdatedState(ZoneId.of("UTC")); state = resource.getTamperLastUpdatedState();
assertTrue(state instanceof DateTimeType); assertTrue(state instanceof DateTimeType);
assertEquals(start, ((DateTimeType) state).getInstant()); assertEquals(start, ((DateTimeType) state).getInstant());
@ -761,7 +754,7 @@ class Clip2DtoTest {
tamperReports.add(new TamperReport().setTamperState("tampered").setLastChanged(start.plusSeconds(1))); tamperReports.add(new TamperReport().setTamperState("tampered").setLastChanged(start.plusSeconds(1)));
resource.setTamperReports(tamperReports); resource.setTamperReports(tamperReports);
assertEquals(OpenClosedType.OPEN, resource.getTamperState()); assertEquals(OpenClosedType.OPEN, resource.getTamperState());
state = resource.getTamperLastUpdatedState(ZoneId.of("UTC")); state = resource.getTamperLastUpdatedState();
assertTrue(state instanceof DateTimeType); assertTrue(state instanceof DateTimeType);
assertEquals(start.plusSeconds(1), ((DateTimeType) state).getInstant()); assertEquals(start.plusSeconds(1), ((DateTimeType) state).getInstant());
@ -771,7 +764,7 @@ class Clip2DtoTest {
tamperReports.add(new TamperReport().setTamperState("not_tampered").setLastChanged(start.plusSeconds(2))); tamperReports.add(new TamperReport().setTamperState("not_tampered").setLastChanged(start.plusSeconds(2)));
resource.setTamperReports(tamperReports); resource.setTamperReports(tamperReports);
assertEquals(OpenClosedType.CLOSED, resource.getTamperState()); assertEquals(OpenClosedType.CLOSED, resource.getTamperState());
state = resource.getTamperLastUpdatedState(ZoneId.of("UTC")); state = resource.getTamperLastUpdatedState();
assertTrue(state instanceof DateTimeType); assertTrue(state instanceof DateTimeType);
assertEquals(start.plusSeconds(2), ((DateTimeType) state).getInstant()); assertEquals(start.plusSeconds(2), ((DateTimeType) state).getInstant());
} }
@ -791,8 +784,7 @@ class Clip2DtoTest {
assertNotNull(enabled); assertNotNull(enabled);
assertTrue(enabled); assertTrue(enabled);
assertEquals(OnOffType.ON, resource.getMotionState()); assertEquals(OnOffType.ON, resource.getMotionState());
assertEquals(new DateTimeType("2020-04-01T20:04:30.395Z"), assertEquals(new DateTimeType("2020-04-01T20:04:30.395Z"), resource.getMotionLastUpdatedState());
resource.getMotionLastUpdatedState(ZoneId.of("UTC")));
} }
void testFixedEffectSetter() { void testFixedEffectSetter() {
@ -929,6 +921,6 @@ class Clip2DtoTest {
assertNotNull(enabled); assertNotNull(enabled);
assertTrue(enabled); assertTrue(enabled);
assertEquals(OnOffType.ON, item.getMotionState()); 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());
} }
} }