From cccb8d0be95a74be8a6ccf48ecedfd46486cfdfd Mon Sep 17 00:00:00 2001 From: Jimmy Tanagra Date: Thu, 28 Nov 2024 22:43:08 +1000 Subject: [PATCH] Rename to getLastStateChange, getLastStateUpdate, getLastState Signed-off-by: Jimmy Tanagra --- .../rest/core/item/EnrichedGroupItemDTO.java | 10 ++++---- .../io/rest/core/item/EnrichedItemDTO.java | 16 ++++++------- .../rest/core/item/EnrichedItemDTOMapper.java | 12 +++++----- .../org/openhab/core/items/GenericItem.java | 24 +++++++++---------- .../java/org/openhab/core/items/Item.java | 6 ++--- .../openhab/core/items/GenericItemTest.java | 24 +++++++++---------- 6 files changed, 46 insertions(+), 46 deletions(-) diff --git a/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/item/EnrichedGroupItemDTO.java b/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/item/EnrichedGroupItemDTO.java index d53413a4957..0881ff75f23 100644 --- a/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/item/EnrichedGroupItemDTO.java +++ b/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/item/EnrichedGroupItemDTO.java @@ -24,11 +24,11 @@ */ public class EnrichedGroupItemDTO extends EnrichedItemDTO { - public EnrichedGroupItemDTO(ItemDTO itemDTO, EnrichedItemDTO[] members, String link, String state, - String previousState, Long lastUpdate, Long lastChange, String transformedState, - StateDescription stateDescription, String unitSymbol) { - super(itemDTO, link, state, previousState, lastUpdate, lastChange, transformedState, stateDescription, null, - unitSymbol); + public EnrichedGroupItemDTO(ItemDTO itemDTO, EnrichedItemDTO[] members, String link, String state, String lastState, + Long lastStateUpdate, Long lastStateChange, String transformedState, StateDescription stateDescription, + String unitSymbol) { + super(itemDTO, link, state, lastState, lastStateUpdate, lastStateChange, transformedState, stateDescription, + null, unitSymbol); this.members = members; this.groupType = ((GroupItemDTO) itemDTO).groupType; this.function = ((GroupItemDTO) itemDTO).function; diff --git a/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/item/EnrichedItemDTO.java b/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/item/EnrichedItemDTO.java index 69123dfbbd3..a7177a5e5d0 100644 --- a/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/item/EnrichedItemDTO.java +++ b/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/item/EnrichedItemDTO.java @@ -33,15 +33,15 @@ public class EnrichedItemDTO extends ItemDTO { public String transformedState; public StateDescription stateDescription; public CommandDescription commandDescription; - public String previousState; - public Long lastUpdate; - public Long lastChange; + public String lastState; + public Long lastStateUpdate; + public Long lastStateChange; public String unitSymbol; public Map metadata; public Boolean editable; - public EnrichedItemDTO(ItemDTO itemDTO, String link, String state, String previousState, Long lastUpdate, - Long lastChange, String transformedState, StateDescription stateDescription, + public EnrichedItemDTO(ItemDTO itemDTO, String link, String state, String lastState, Long lastStateUpdate, + Long lastStateChange, String transformedState, StateDescription stateDescription, CommandDescription commandDescription, String unitSymbol) { this.type = itemDTO.type; this.name = itemDTO.name; @@ -54,9 +54,9 @@ public EnrichedItemDTO(ItemDTO itemDTO, String link, String state, String previo this.transformedState = transformedState; this.stateDescription = stateDescription; this.commandDescription = commandDescription; - this.previousState = previousState; - this.lastUpdate = lastUpdate; - this.lastChange = lastChange; + this.lastState = lastState; + this.lastStateUpdate = lastStateUpdate; + this.lastStateChange = lastStateChange; this.unitSymbol = unitSymbol; } } diff --git a/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/item/EnrichedItemDTOMapper.java b/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/item/EnrichedItemDTOMapper.java index 4c1e71da828..dd41bfa8e54 100644 --- a/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/item/EnrichedItemDTOMapper.java +++ b/bundles/org.openhab.core.io.rest.core/src/main/java/org/openhab/core/io/rest/core/item/EnrichedItemDTOMapper.java @@ -92,10 +92,10 @@ private static EnrichedItemDTO map(Item item, ItemDTO itemDTO, boolean drillDown } StateDescription stateDescription = considerTransformation(item.getStateDescription(locale)); - String previousState = Optional.ofNullable(item.getPreviousState()).map(State::toFullString).orElse(null); - Long lastUpdate = Optional.ofNullable(item.getLastUpdate()).map(zdt -> zdt.toInstant().toEpochMilli()) + String lastState = Optional.ofNullable(item.getLastState()).map(State::toFullString).orElse(null); + Long lastStateUpdate = Optional.ofNullable(item.getLastStateUpdate()).map(zdt -> zdt.toInstant().toEpochMilli()) .orElse(null); - Long lastChange = Optional.ofNullable(item.getLastChange()).map(zdt -> zdt.toInstant().toEpochMilli()) + Long lastStateChange = Optional.ofNullable(item.getLastStateChange()).map(zdt -> zdt.toInstant().toEpochMilli()) .orElse(null); final String link; @@ -131,10 +131,10 @@ private static EnrichedItemDTO map(Item item, ItemDTO itemDTO, boolean drillDown } else { memberDTOs = new EnrichedItemDTO[0]; } - enrichedItemDTO = new EnrichedGroupItemDTO(itemDTO, memberDTOs, link, state, previousState, lastUpdate, - lastChange, transformedState, stateDescription, unitSymbol); + enrichedItemDTO = new EnrichedGroupItemDTO(itemDTO, memberDTOs, link, state, lastState, lastStateUpdate, + lastStateChange, transformedState, stateDescription, unitSymbol); } else { - enrichedItemDTO = new EnrichedItemDTO(itemDTO, link, state, previousState, lastUpdate, lastChange, + enrichedItemDTO = new EnrichedItemDTO(itemDTO, link, state, lastState, lastStateUpdate, lastStateChange, transformedState, stateDescription, item.getCommandDescription(locale), unitSymbol); } diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/items/GenericItem.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/items/GenericItem.java index 48152b3c04f..d7a3ba5e12d 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/items/GenericItem.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/items/GenericItem.java @@ -78,10 +78,10 @@ public abstract class GenericItem implements ActiveItem { protected final String type; protected State state = UnDefType.NULL; - protected @Nullable State previousState; + protected @Nullable State lastState; - protected @Nullable ZonedDateTime lastUpdate; - protected @Nullable ZonedDateTime lastChange; + protected @Nullable ZonedDateTime lastStateUpdate; + protected @Nullable ZonedDateTime lastStateChange; protected @Nullable String label; @@ -109,18 +109,18 @@ public State getState() { } @Override - public @Nullable State getPreviousState() { - return previousState; + public @Nullable State getLastState() { + return lastState; } @Override - public @Nullable ZonedDateTime getLastUpdate() { - return lastUpdate; + public @Nullable ZonedDateTime getLastStateUpdate() { + return lastStateUpdate; } @Override - public @Nullable ZonedDateTime getLastChange() { - return lastChange; + public @Nullable ZonedDateTime getLastStateChange() { + return lastStateChange; } @Override @@ -243,15 +243,15 @@ protected final void applyState(State state) { boolean stateChanged = !oldState.equals(state); this.state = state; if (stateChanged) { - previousState = oldState; // update before we notify listeners + lastState = oldState; // update before we notify listeners } notifyListeners(oldState, state); sendStateUpdatedEvent(state); if (stateChanged) { sendStateChangedEvent(state, oldState); - lastChange = now; // update after we've notified listeners + lastStateChange = now; // update after we've notified listeners } - lastUpdate = now; + lastStateUpdate = now; } /** diff --git a/bundles/org.openhab.core/src/main/java/org/openhab/core/items/Item.java b/bundles/org.openhab.core/src/main/java/org/openhab/core/items/Item.java index 393632d6c1c..8d71b860eaa 100644 --- a/bundles/org.openhab.core/src/main/java/org/openhab/core/items/Item.java +++ b/bundles/org.openhab.core/src/main/java/org/openhab/core/items/Item.java @@ -63,7 +63,7 @@ public interface Item extends Identifiable { * @return the previous state of the item, or null if the item has never been changed. */ @Nullable - State getPreviousState(); + State getLastState(); /** * Returns the time the item was last updated. @@ -71,7 +71,7 @@ public interface Item extends Identifiable { * @return the time the item was last updated, or null if the item has never been updated. */ @Nullable - ZonedDateTime getLastUpdate(); + ZonedDateTime getLastStateUpdate(); /** * Returns the time the item was last changed. @@ -79,7 +79,7 @@ public interface Item extends Identifiable { * @return the time the item was last changed, or null if the item has never been changed. */ @Nullable - ZonedDateTime getLastChange(); + ZonedDateTime getLastStateChange(); /** * returns the name of the item diff --git a/bundles/org.openhab.core/src/test/java/org/openhab/core/items/GenericItemTest.java b/bundles/org.openhab.core/src/test/java/org/openhab/core/items/GenericItemTest.java index b33cdd18822..f7226ba49a2 100644 --- a/bundles/org.openhab.core/src/test/java/org/openhab/core/items/GenericItemTest.java +++ b/bundles/org.openhab.core/src/test/java/org/openhab/core/items/GenericItemTest.java @@ -138,44 +138,44 @@ public void testGetStateAsWithNull() { } @Test - public void testGetLastUpdate() { + public void testGetLastStateUpdate() { TestItem item = new TestItem("member1"); - assertNull(item.getLastUpdate()); + assertNull(item.getLastStateUpdate()); item.setState(PercentType.HUNDRED); - assertThat(item.getLastUpdate().toInstant().toEpochMilli() * 1.0, + assertThat(item.getLastStateUpdate().toInstant().toEpochMilli() * 1.0, is(closeTo(ZonedDateTime.now().toInstant().toEpochMilli(), 5))); } @Test - public void testGetLastChange() throws InterruptedException { + public void testGetLastStateChange() throws InterruptedException { TestItem item = new TestItem("member1"); - assertNull(item.getLastChange()); + assertNull(item.getLastStateChange()); item.setState(PercentType.HUNDRED); ZonedDateTime initialChangeTime = ZonedDateTime.now(); - assertThat(item.getLastChange().toInstant().toEpochMilli() * 1.0, + assertThat(item.getLastStateChange().toInstant().toEpochMilli() * 1.0, is(closeTo(initialChangeTime.toInstant().toEpochMilli(), 5))); Thread.sleep(50); item.setState(PercentType.HUNDRED); - assertThat(item.getLastChange().toInstant().toEpochMilli() * 1.0, + assertThat(item.getLastStateChange().toInstant().toEpochMilli() * 1.0, is(closeTo(initialChangeTime.toInstant().toEpochMilli(), 5))); Thread.sleep(50); ZonedDateTime secondChangeTime = ZonedDateTime.now(); item.setState(PercentType.ZERO); - assertThat(item.getLastChange().toInstant().toEpochMilli() * 1.0, + assertThat(item.getLastStateChange().toInstant().toEpochMilli() * 1.0, is(closeTo(secondChangeTime.toInstant().toEpochMilli(), 5))); } @Test - public void testGetPreviousState() { + public void testGetLastState() { TestItem item = new TestItem("member1"); assertEquals(UnDefType.NULL, item.getState()); - assertNull(item.getPreviousState()); + assertNull(item.getLastState()); item.setState(PercentType.HUNDRED); - assertEquals(UnDefType.NULL, item.getPreviousState()); + assertEquals(UnDefType.NULL, item.getLastState()); item.setState(PercentType.ZERO); - assertEquals(PercentType.HUNDRED, item.getPreviousState()); + assertEquals(PercentType.HUNDRED, item.getLastState()); } @Test