Skip to content

Commit

Permalink
[icalendar] Fix race condition while initialization of EventFilterHan…
Browse files Browse the repository at this point in the history
…dler (#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>
Signed-off-by: Christian Grasser <info@christiangrasser.at>
  • Loading branch information
2 people authored and Christian Grasser committed Dec 7, 2020
1 parent 05b7bbd commit 7a140ab
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ public void dispose() {
@Override
public void handleCommand(ChannelUID channelUID, Command command) {
if (command instanceof RefreshType) {
if (initFinished) {
updateStates();
}
updateStates();
}
}

Expand All @@ -121,14 +119,13 @@ public void initialize() {
}
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
Expand Down Expand Up @@ -257,6 +254,10 @@ private void updateChannelSet(EventFilterConfiguration config) {
* 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!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ public void onCalendarUpdated() {
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);
Expand Down

0 comments on commit 7a140ab

Please sign in to comment.