Fix IndexOutOfBoundsException in aggregator function (#11113)

Signed-off-by: Anders Alfredsson <andersb86@gmail.com>
This commit is contained in:
Anders Alfredsson 2021-08-22 11:53:11 +02:00 committed by GitHub
parent 9fed16d8bb
commit c084ec3a5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 0 deletions

View File

@ -34,6 +34,7 @@ The complete channel identifier is the channel group id (`hour_<offset>` or `day
or the number of hours/days from now) + the channel id, concatenated with a `#`. or the number of hours/days from now) + the channel id, concatenated with a `#`.
Examples: Examples:
* Temperature for the current hour: `hour_0#t` * Temperature for the current hour: `hour_0#t`
* Total precipitation 3 days from now: `day_3#ptotal` * Total precipitation 3 days from now: `day_3#ptotal`

View File

@ -64,6 +64,9 @@ public class ForecastAggregator {
*/ */
public static Optional<BigDecimal> total(TimeSeries timeSeries, int dayOffset, String parameter) { public static Optional<BigDecimal> total(TimeSeries timeSeries, int dayOffset, String parameter) {
List<Forecast> dayForecasts = timeSeries.getDay(dayOffset); List<Forecast> dayForecasts = timeSeries.getDay(dayOffset);
if (dayForecasts.size() == 1) {
return dayForecasts.get(0).getParameter(parameter);
}
List<BigDecimal> values = new ArrayList<>(); List<BigDecimal> values = new ArrayList<>();
for (int i = 0; i < dayForecasts.size(); i++) { for (int i = 0; i < dayForecasts.size(); i++) {
Forecast current = dayForecasts.get(i); Forecast current = dayForecasts.get(i);

View File

@ -254,6 +254,7 @@ public class SmhiHandler extends BaseThingHandler {
} catch (RuntimeException e) { } catch (RuntimeException e) {
logger.warn("Unexpected exception occurred, please report to the developers: {}: {}", e.getClass(), logger.warn("Unexpected exception occurred, please report to the developers: {}: {}", e.getClass(),
e.getMessage()); e.getMessage());
logger.debug("Details: ", e);
} }
} }