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

[linky] Set channel to UNDEF when data not yet available #9774

Merged
merged 1 commit into from
Jan 12, 2021
Merged
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 @@ -16,6 +16,7 @@

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.time.temporal.WeekFields;
Expand Down Expand Up @@ -214,9 +215,11 @@ private synchronized void updatePowerData() {
*/
private synchronized void updateDailyData() {
if (isLinked(YESTERDAY)) {
cachedDailyData.getValue().ifPresent(values -> {
cachedDailyData.getValue().ifPresentOrElse(values -> {
Aggregate days = values.aggregats.days;
updateKwhChannel(YESTERDAY, days.datas.get(days.datas.size() - 1));
}, () -> {
updateKwhChannel(YESTERDAY, Double.NaN);
});
}
}
Expand All @@ -226,7 +229,7 @@ private synchronized void updateDailyData() {
*/
private synchronized void updateWeeklyData() {
if (isLinked(LAST_WEEK) || isLinked(THIS_WEEK)) {
cachedDailyData.getValue().ifPresent(values -> {
cachedDailyData.getValue().ifPresentOrElse(values -> {
Aggregate days = values.aggregats.days;
int idxLast = days.periodes.get(days.periodes.size() - 1).dateDebut.get(weekFields.dayOfWeek()) == 7 ? 2
: 1;
Expand All @@ -239,6 +242,13 @@ private synchronized void updateWeeklyData() {
} else {
updateKwhChannel(THIS_WEEK, 0.0);
}
}, () -> {
if (ZonedDateTime.now().get(weekFields.dayOfWeek()) == 1) {
updateKwhChannel(THIS_WEEK, 0.0);
updateKwhChannel(LAST_WEEK, Double.NaN);
} else {
updateKwhChannel(THIS_WEEK, Double.NaN);
}
});
}
}
Expand All @@ -248,14 +258,21 @@ private synchronized void updateWeeklyData() {
*/
private synchronized void updateMonthlyData() {
if (isLinked(LAST_MONTH) || isLinked(THIS_MONTH)) {
cachedMonthlyData.getValue().ifPresent(values -> {
cachedMonthlyData.getValue().ifPresentOrElse(values -> {
Aggregate months = values.aggregats.months;
updateKwhChannel(LAST_MONTH, months.datas.get(0));
if (months.datas.size() > 1) {
updateKwhChannel(THIS_MONTH, months.datas.get(1));
} else {
updateKwhChannel(THIS_MONTH, 0.0);
}
}, () -> {
if (ZonedDateTime.now().getDayOfMonth() == 1) {
updateKwhChannel(THIS_MONTH, 0.0);
updateKwhChannel(LAST_MONTH, Double.NaN);
} else {
updateKwhChannel(THIS_MONTH, Double.NaN);
}
});
}
}
Expand All @@ -265,14 +282,21 @@ private synchronized void updateMonthlyData() {
*/
private synchronized void updateYearlyData() {
if (isLinked(LAST_YEAR) || isLinked(THIS_YEAR)) {
cachedYearlyData.getValue().ifPresent(values -> {
cachedYearlyData.getValue().ifPresentOrElse(values -> {
Aggregate years = values.aggregats.years;
updateKwhChannel(LAST_YEAR, years.datas.get(0));
if (years.datas.size() > 1) {
updateKwhChannel(THIS_YEAR, years.datas.get(1));
} else {
updateKwhChannel(THIS_YEAR, 0.0);
}
}, () -> {
if (ZonedDateTime.now().getDayOfYear() == 1) {
updateKwhChannel(THIS_YEAR, 0.0);
updateKwhChannel(LAST_YEAR, Double.NaN);
} else {
updateKwhChannel(THIS_YEAR, Double.NaN);
}
});
}
}
Expand Down