From de390b96beb7bf4b31c6a1ae64fa5eee8125bb60 Mon Sep 17 00:00:00 2001 From: Michael Wodniok Date: Sat, 5 Dec 2020 06:35:14 +0100 Subject: [PATCH] [icalendar] Fix race condition while initialization of EventFilterHandler (#9230) * [icalendar] Fix race condition while initialization of EventFilterHandler Should fix #9029. The channels do not get updated as the known channels by the binding where only updated if Bridge was already online while initializing EventFilterHandler. Also added a bit more output. * [icalendar] use implicit conversion to string for logging Signed-off-by: Michael Wodniok Co-authored-by: Connor Petty --- .../internal/handler/EventFilterHandler.java | 15 ++++++++------- .../internal/handler/ICalendarHandler.java | 1 + 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/bundles/org.openhab.binding.icalendar/src/main/java/org/openhab/binding/icalendar/internal/handler/EventFilterHandler.java b/bundles/org.openhab.binding.icalendar/src/main/java/org/openhab/binding/icalendar/internal/handler/EventFilterHandler.java index ac108ec08c1..b2ed561bf0f 100644 --- a/bundles/org.openhab.binding.icalendar/src/main/java/org/openhab/binding/icalendar/internal/handler/EventFilterHandler.java +++ b/bundles/org.openhab.binding.icalendar/src/main/java/org/openhab/binding/icalendar/internal/handler/EventFilterHandler.java @@ -95,9 +95,7 @@ public class EventFilterHandler extends BaseThingHandler implements CalendarUpda @Override public void handleCommand(ChannelUID channelUID, Command command) { if (command instanceof RefreshType) { - if (initFinished) { - updateStates(); - } + updateStates(); } } @@ -121,14 +119,13 @@ public class EventFilterHandler extends BaseThingHandler implements CalendarUpda } configuration = config; + updateChannelSet(config); + initFinished = true; if (iCalendarBridge.getStatus() != ThingStatus.ONLINE) { updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.BRIDGE_OFFLINE); return; - } else { - updateChannelSet(config); - updateStates(); } - initFinished = true; + updateStates(); } @Override @@ -257,6 +254,10 @@ public class EventFilterHandler extends BaseThingHandler implements CalendarUpda * Updates all states and channels. Reschedules an update if no error occurs. */ private void updateStates() { + if (!initFinished) { + logger.debug("Ignoring call for updating states as this instance is not initialized yet."); + return; + } final Bridge iCalendarBridge = getBridge(); if (iCalendarBridge == null) { logger.debug("Bridge not instantiated!"); diff --git a/bundles/org.openhab.binding.icalendar/src/main/java/org/openhab/binding/icalendar/internal/handler/ICalendarHandler.java b/bundles/org.openhab.binding.icalendar/src/main/java/org/openhab/binding/icalendar/internal/handler/ICalendarHandler.java index deb7c4add60..384d6000277 100644 --- a/bundles/org.openhab.binding.icalendar/src/main/java/org/openhab/binding/icalendar/internal/handler/ICalendarHandler.java +++ b/bundles/org.openhab.binding.icalendar/src/main/java/org/openhab/binding/icalendar/internal/handler/ICalendarHandler.java @@ -183,6 +183,7 @@ public class ICalendarHandler extends BaseBridgeHandler implements CalendarUpdat ThingHandler handler = childThing.getHandler(); if (handler instanceof CalendarUpdateListener) { try { + logger.trace("Notifying {} about fresh calendar.", handler.getThing().getUID()); ((CalendarUpdateListener) handler).onCalendarUpdated(); } catch (Exception e) { logger.trace("The update of a child handler failed. Ignoring.", e);