mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
Fix last hour not being considered for best price (#17731)
Resolves #17316 Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk> Signed-off-by: Ciprian Pascu <contact@ciprianpascu.ro>
This commit is contained in:
parent
92daa5d319
commit
dab00add80
@ -142,7 +142,7 @@ public class AwattarBestPriceHandler extends BaseThingHandler {
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
@ -239,8 +239,20 @@ public class AwattarBridgeHandler extends BaseBridgeHandler {
|
||||
|
||||
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
|
||||
|
@ -48,6 +48,7 @@ public record TimeRange(long start, long end) implements Comparable<TimeRange> {
|
||||
* @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);
|
||||
}
|
||||
|
@ -150,9 +150,17 @@ public class AwattarBridgeHandlerTest extends JavaTest {
|
||||
}
|
||||
|
||||
@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));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user