Rename to getLastStateChange, getLastStateUpdate, getLastState

Signed-off-by: Jimmy Tanagra <jcode@tanagra.id.au>
pull/4351/head
Jimmy Tanagra 2024-11-28 22:43:08 +10:00
parent 178df650d9
commit cccb8d0be9
6 changed files with 46 additions and 46 deletions

View File

@ -24,11 +24,11 @@ import org.openhab.core.types.StateDescription;
*/
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;

View File

@ -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<String, Object> 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 class EnrichedItemDTO extends ItemDTO {
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;
}
}

View File

@ -92,10 +92,10 @@ public class EnrichedItemDTOMapper {
}
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 @@ public class EnrichedItemDTOMapper {
} 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);
}

View File

@ -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 abstract class GenericItem implements ActiveItem {
}
@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 @@ public abstract class GenericItem implements ActiveItem {
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;
}
/**

View File

@ -63,7 +63,7 @@ public interface Item extends Identifiable<String> {
* @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<String> {
* @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<String> {
* @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

View File

@ -138,44 +138,44 @@ public class GenericItemTest {
}
@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