Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[awattar] Fix last hour not being considered for best price #17731

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public void refreshChannel(ChannelUID channelUID) {
}
AwattarBestPriceConfiguration config = getConfigAs(AwattarBestPriceConfiguration.class);
TimeRange timerange = getRange(config.rangeStart, config.rangeDuration, bridgeHandler.getTimeZone());
if (!(bridgeHandler.containsPriceFor(timerange.start()) && bridgeHandler.containsPriceFor(timerange.end()))) {
if (!(bridgeHandler.containsPriceFor(timerange))) {
updateState(channelUID, state);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,20 @@ public synchronized SortedSet<AwattarPrice> getPrices() {

public boolean containsPriceFor(long timestamp) {
SortedSet<AwattarPrice> localPrices = getPrices();
return localPrices != null && localPrices.first().timerange().start() <= timestamp
&& localPrices.last().timerange().end() > timestamp;
if (localPrices == null) {
return false;
}
return new TimeRange(localPrices.first().timerange().start(), localPrices.last().timerange().end())
.contains(timestamp);
}

public boolean containsPriceFor(TimeRange timeRange) {
SortedSet<AwattarPrice> localPrices = getPrices();
if (localPrices == null) {
return false;
}
return new TimeRange(localPrices.first().timerange().start(), localPrices.last().timerange().end())
.contains(timeRange);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public boolean contains(TimeRange other) {
* @param o the object to be compared
* @return the result of {@link Long#compare(long, long)} for the {@link #start} timestamps
*/
@Override
public int compareTo(TimeRange o) {
return Long.compare(start, o.start);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,17 @@ void testGetPriceForFail() {
}

@Test
void testContainsPrizeFor() {
void testContainsPriceForTimestamp() {
assertThat(bridgeHandler.containsPriceFor(new TimeRange(1618503200000L, 1718316000000L)), is(false));
assertThat(bridgeHandler.containsPriceFor(new TimeRange(1618503200000L, 1718503200000L)), is(false));
assertThat(bridgeHandler.containsPriceFor(new TimeRange(1718503200000L, 1718575200000L)), is(true));
}

@Test
void testContainsPriceForRange() {
assertThat(bridgeHandler.containsPriceFor(1618503200000L), is(false));
assertThat(bridgeHandler.containsPriceFor(1718503200000L), is(true));
assertThat(bridgeHandler.containsPriceFor(1718575200000L), is(false));
assertThat(bridgeHandler.containsPriceFor(1818503200000L), is(false));
}

Expand Down