[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 <michi@noorganization.org>
Co-authored-by: Connor Petty <mistercpp2000+gitsignoff@gmail.com>
This commit is contained in:
Michael Wodniok 2020-12-05 06:35:14 +01:00 committed by GitHub
parent 05b7bbdccf
commit de390b96be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 7 deletions

View File

@ -95,11 +95,9 @@ public class EventFilterHandler extends BaseThingHandler implements CalendarUpda
@Override
public void handleCommand(ChannelUID channelUID, Command command) {
if (command instanceof RefreshType) {
if (initFinished) {
updateStates();
}
}
}
@Override
public void initialize() {
@ -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!");

View File

@ -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);