Skip to content

Commit

Permalink
Fetch data further back to ensure battery device has been online
Browse files Browse the repository at this point in the history
Signed-off-by: Arne Seime <[email protected]>
  • Loading branch information
seime committed Jan 25, 2022
1 parent 407f68e commit 16fada0
Showing 1 changed file with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,15 @@ protected Measurement getLastDataPoint(Appliance appliance) {
private @Nullable ApplianceData getApplianceData(Appliance appliance) {
// Dates are stripped of time part inside library
Instant now = Instant.now();
Instant yesterday = now.minus(1, ChronoUnit.DAYS);
Instant twoDaysAgo = now.minus(2, ChronoUnit.DAYS); // Devices only report once a day - at best
Instant tomorrow = now.plus(1, ChronoUnit.DAYS);
OndusService service = getOndusService();
if (service == null) {
return null;
}
try {
logger.debug("Fetching data for {} from {} to {}", thing.getUID(), yesterday, tomorrow);
BaseApplianceData applianceData = service.applianceData(appliance, yesterday, tomorrow).orElse(null);
logger.debug("Fetching data for {} from {} to {}", thing.getUID(), twoDaysAgo, tomorrow);
BaseApplianceData applianceData = service.applianceData(appliance, twoDaysAgo, tomorrow).orElse(null);
if (applianceData != null) {
if (applianceData.getType() != Appliance.TYPE) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "@text/error.notsense");
Expand All @@ -175,7 +175,6 @@ protected Measurement getLastDataPoint(Appliance appliance) {
public void handleCommand(ChannelUID channelUID, Command command) {
if (command instanceof RefreshType) {
updateChannels();
return;
}
}
}

0 comments on commit 16fada0

Please sign in to comment.