-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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] Feature/push code coverage #17752
base: main
Are you sure you want to change the base?
[awattar] Feature/push code coverage #17752
Conversation
@tl-photography - thanks. Did you intend to include the two commits from #17729? In that case, we need to add label "awaiting other PR" to mention this dependency. |
Ah ok, I marked it as draft only. Can I set this label too, otherwise please do so. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks for your work and your patience!
I just merged #17729 |
Thanks! PR should be good. 👍 Edit: Should I rebase? |
Yes, please. |
074b441
to
88312d1
Compare
done |
...ar/src/main/java/org/openhab/binding/awattar/internal/AwattarConsecutiveBestPriceResult.java
Outdated
Show resolved
Hide resolved
...nding.awattar/src/main/java/org/openhab/binding/awattar/internal/AwattarBestPriceResult.java
Outdated
Show resolved
Hide resolved
@@ -163,7 +162,7 @@ public void refreshChannel(ChannelUID channelUID) { | |||
long diff; | |||
switch (channelId) { | |||
case CHANNEL_ACTIVE: | |||
state = OnOffType.from(result.isActive()); | |||
state = OnOffType.from(result.isActive(getNow(zoneId).toInstant())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here and other places below: This can be simplified, there is no reason to go through the trouble of getting a ZonedDateTime
just to discard to time-zone again when converting back to Instant
:
state = OnOffType.from(result.isActive(getNow(zoneId).toInstant())); | |
state = OnOffType.from(result.isActive(Instant.now())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main reason for this change is to access the instant in the utests for stubbing.
I did not find a way with the available framework to stub the const Instant.now()
method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hwo about this change in 622cfc0
would this work for you?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might also be able to provide a Clock object for mocking this. See for example:
Lines 41 to 59 in 98d2579
private final Clock clock; | |
public PriceListParser() { | |
this(Clock.system(EnergiDataServiceBindingConstants.DATAHUB_TIMEZONE)); | |
} | |
public PriceListParser(Clock clock) { | |
this.clock = clock; | |
} | |
public Map<Instant, BigDecimal> toHourly(Collection<DatahubPricelistRecord> records) { | |
Instant firstHourStart = Instant.now(clock) | |
.minus(ElectricityPriceSubscriptionCache.NUMBER_OF_HISTORIC_HOURS, ChronoUnit.HOURS) | |
.truncatedTo(ChronoUnit.HOURS); | |
Instant lastHourStart = Instant.now(clock).truncatedTo(ChronoUnit.HOURS).plus(2, ChronoUnit.DAYS) | |
.truncatedTo(ChronoUnit.DAYS); | |
return toHourly(records, firstHourStart, lastHourStart); | |
} |
and:
Lines 67 to 79 in 98d2579
@Test | |
void toHourlyNoChanges() throws IOException { | |
PriceListParser priceListParser = new PriceListParser( | |
Clock.fixed(Instant.parse("2023-01-23T12:00:00Z"), EnergiDataServiceBindingConstants.DATAHUB_TIMEZONE)); | |
DatahubPricelistRecords records = getObjectFromJson("DatahubPricelistN1.json", DatahubPricelistRecords.class); | |
Map<Instant, BigDecimal> tariffMap = priceListParser.toHourly(Arrays.stream(records.records()).toList()); | |
assertThat(tariffMap.size(), is(60)); | |
assertThat(tariffMap.get(Instant.parse("2023-01-23T15:00:00Z")), is(equalTo(new BigDecimal("0.432225")))); | |
assertThat(tariffMap.get(Instant.parse("2023-01-23T16:00:00Z")), is(equalTo(new BigDecimal("1.05619")))); | |
assertThat(tariffMap.get(Instant.parse("2023-01-24T15:00:00Z")), is(equalTo(new BigDecimal("0.432225")))); | |
assertThat(tariffMap.get(Instant.parse("2023-01-24T16:00:00Z")), is(equalTo(new BigDecimal("1.05619")))); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just had a look and it seems the example you send me implements a Constructor where the clock object is initialized exactly for the reason of testing.
In the production code, only the constructor without the parameter is used.
I can change the code, but i think there is not much difference between the two approaches.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i have worked on it and changed most of the code to a clock object to have the same look and feel.
...ttar/src/main/java/org/openhab/binding/awattar/internal/handler/AwattarBestPriceHandler.java
Outdated
Show resolved
Hide resolved
...ttar/src/main/java/org/openhab/binding/awattar/internal/handler/AwattarBestPriceHandler.java
Outdated
Show resolved
Hide resolved
...tar/src/test/java/org/openhab/binding/awattar/internal/handler/AwattarBridgeHandlerTest.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Thomas Leber <[email protected]>
Signed-off-by: Thomas Leber <[email protected]>
Signed-off-by: Thomas Leber <[email protected]>
Signed-off-by: Thomas Leber <[email protected]>
Signed-off-by: Thomas Leber <[email protected]>
Signed-off-by: Thomas Leber <[email protected]>
Signed-off-by: Thomas Leber <[email protected]>
c2c8b60
to
c5eec4e
Compare
i had conflicts and resolved them via rebase |
Signed-off-by: Thomas Leber <[email protected]>
I also added now tests for the refresh logic, since this was easy to add after the clock rework. |
PR does not change behaviour.
Only pushes code coverage and code maintainability.