From cb60d891fbb60f15ec3ed1ac8ecc07364d753dd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans=20B=C3=B6hm?= Date: Sat, 7 May 2022 19:01:38 +0200 Subject: [PATCH] [openweathermap] Fix display of alert data (#12697) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix display of alert data * improve javadoc * add javadoc to updateMinutelyForecastChannel Signed-off-by: Hans Böhm --- .../handler/OpenWeatherMapOneCallHandler.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/bundles/org.openhab.binding.openweathermap/src/main/java/org/openhab/binding/openweathermap/internal/handler/OpenWeatherMapOneCallHandler.java b/bundles/org.openhab.binding.openweathermap/src/main/java/org/openhab/binding/openweathermap/internal/handler/OpenWeatherMapOneCallHandler.java index 7c7611d39..329d0dd52 100644 --- a/bundles/org.openhab.binding.openweathermap/src/main/java/org/openhab/binding/openweathermap/internal/handler/OpenWeatherMapOneCallHandler.java +++ b/bundles/org.openhab.binding.openweathermap/src/main/java/org/openhab/binding/openweathermap/internal/handler/OpenWeatherMapOneCallHandler.java @@ -263,7 +263,7 @@ public class OpenWeatherMapOneCallHandler extends AbstractOpenWeatherMapHandler } Matcher alertsMatcher = CHANNEL_GROUP_ALERTS_PREFIX_PATTERN.matcher(channelGroupId); if (alertsMatcher.find() && (i = Integer.parseInt(alertsMatcher.group(1))) >= 1) { - updateAlertsChannel(channelUID, i); + updateAlertsChannel(channelUID, i - 1); break; } break; @@ -371,6 +371,12 @@ public class OpenWeatherMapOneCallHandler extends AbstractOpenWeatherMapHandler } } + /** + * Update the channel from the last OpenWeatherMap data retrieved. + * + * @param channelUID the id identifying the channel to be updated + * @param count the index of the minutely data referenced by the channel (minute 1 is count 0) + */ private void updateMinutelyForecastChannel(ChannelUID channelUID, int count) { String channelId = channelUID.getIdWithoutGroup(); String channelGroupId = channelUID.getGroupId(); @@ -410,7 +416,7 @@ public class OpenWeatherMapOneCallHandler extends AbstractOpenWeatherMapHandler * Update the channel from the last OpenWeatherMap data retrieved. * * @param channelUID the id identifying the channel to be updated - * @param count the number of the hour referenced by the channel + * @param count the index of the hourly data referenced by the channel (hour 1 is count 0) */ private void updateHourlyForecastChannel(ChannelUID channelUID, int count) { String channelId = channelUID.getIdWithoutGroup(); @@ -509,7 +515,7 @@ public class OpenWeatherMapOneCallHandler extends AbstractOpenWeatherMapHandler * Update the channel from the last OpenWeatherMap data retrieved. * * @param channelUID the id identifying the channel to be updated - * @param count + * @param count the index of the daily data referenced by the channel (today is count 0) */ private void updateDailyForecastChannel(ChannelUID channelUID, int count) { String channelId = channelUID.getIdWithoutGroup(); @@ -672,7 +678,7 @@ public class OpenWeatherMapOneCallHandler extends AbstractOpenWeatherMapHandler * Update the channel from the last OpenWeaterhMap data retrieved. * * @param channelUID the id identifying the channel to be updated - * @param count + * @param count the index of the alert data referenced by the channel (alert 1 is count 0) */ private void updateAlertsChannel(ChannelUID channelUID, int count) { String channelId = channelUID.getIdWithoutGroup(); @@ -681,7 +687,7 @@ public class OpenWeatherMapOneCallHandler extends AbstractOpenWeatherMapHandler List alerts = localWeatherData != null ? localWeatherData.alerts : null; State state = UnDefType.UNDEF; if (alerts != null && alerts.size() > count) { - Alert alert = alerts.get(count - 1); + Alert alert = alerts.get(count); switch (channelId) { case CHANNEL_ALERT_EVENT: state = getStringTypeState(alert.event);