Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[hdpowerview] Timing dependency during initialization of shades #12071

Closed
jlaur opened this issue Jan 18, 2022 · 0 comments · Fixed by #12113 or #12259
Closed

[hdpowerview] Timing dependency during initialization of shades #12071

jlaur opened this issue Jan 18, 2022 · 0 comments · Fixed by #12113 or #12259
Assignees
Labels
enhancement An enhancement or new feature for an existing add-on

Comments

@jlaur
Copy link
Contributor

jlaur commented Jan 18, 2022

#11707 fixed an issue with shades going ONLINE initially, then into OFFLINE with communication error for a minute. This fix was correct, but not enough.

#12002 changed this behavior to initialize to UNKNOWN instead of ONLINE - c8647e8. This makes sense since we don't know if it's online until we have received data. It could even be unknown to the hub if configured wrongly.

However, this last change revealed a problem that was luring since the beginning. Some shades will go ONLINE before switching state to UNKNOWN, then only back to ONLINE after a minute.

After analyzing this again I found the real issue. Look at this example (id 36321 is blind11):

2022-01-18 16:59:45.298 [DEBUG] [ternal.handler.HDPowerViewHubHandler] - Initializing hub
2022-01-18 16:59:45.311 [DEBUG] [ternal.handler.HDPowerViewHubHandler] - Scheduling poll for 5000 ms out, then every 60000 ms
2022-01-18 16:59:50.313 [DEBUG] [ternal.handler.HDPowerViewHubHandler] - Polling for state
2022-01-18 16:59:50.445 [DEBUG] [ternal.handler.HDPowerViewHubHandler] - Received data for 11 shades
2022-01-18 16:59:50.448 [DEBUG] [ternal.handler.HDPowerViewHubHandler] - Shade '24927' handler not initialized
[...]
2022-01-18 16:59:50.465 [DEBUG] [ternal.handler.HDPowerViewHubHandler] - Updating shade '36321'
2022-01-18 16:59:50.555 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'hdpowerview:shade:hub:blind11' changed from UNINITIALIZED (BRIDGE_UNINITIALIZED) to ONLINE
2022-01-18 16:59:50.562 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'hdpowerview:shade:hub:blind11' changed from ONLINE to INITIALIZING
2022-01-18 16:59:50.565 [DEBUG] [rnal.handler.HDPowerViewShadeHandler] - Initializing shade handler
2022-01-18 16:59:54.368 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'hdpowerview:shade:hub:blind11' changed from INITIALIZING to UNKNOWN
2022-01-18 17:01:25.971 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'hdpowerview:shade:hub:blind11' changed from UNKNOWN to ONLINE

Timeline of events:

  • Hub is initialized and poll job is scheduled after 5 seconds.
  • Shade data is fetched by hub handler, but shade handlers are not yet initialized.
  • Some shade handlers may exist even if they are not initialized.
  • Those that exists will receive data and marked as ONLINE.
  • During initialization they will then be reset to UNKNOWN.

It's possible that the 5 second delay in starting the job was some kind of work-around for this issue. However, with a slow system (Raspberry Pi 3) and many shades (I have 11) this assumption about when handlers would be initialized is false.

Problem is here, in HDPowerViewHubHandler:

    private void updateShadeThing(String shadeId, Thing thing, @Nullable ShadeData shadeData) {
        HDPowerViewShadeHandler thingHandler = ((HDPowerViewShadeHandler) thing.getHandler());
        if (thingHandler == null) {
            logger.debug("Shade '{}' handler not initialized", shadeId);
            return;
        }
        if (shadeData == null) {
            logger.debug("Shade '{}' has no data in hub", shadeId);
        } else {
            logger.debug("Updating shade '{}'", shadeId);
        }
        thingHandler.onReceiveUpdate(shadeData);
    }

This does not consider the status of the shade things, only if it's possible to get the handler.

Solution requirements:

  • Do not introduce a delay in initializing shades, i.e. wait up to one minute for polling.
  • Get rid of the 5 second initial delay.

Proposal:

@jlaur jlaur added the enhancement An enhancement or new feature for an existing add-on label Jan 18, 2022
@jlaur jlaur changed the title [hdpowerview] Timing during initialization of shades [hdpowerview] Timing dependency during initialization of shades Jan 18, 2022
@jlaur jlaur self-assigned this Jan 24, 2022
jlaur added a commit to jlaur/openhab-addons that referenced this issue Jan 24, 2022
jlaur added a commit to jlaur/openhab-addons that referenced this issue Jan 25, 2022
jlaur added a commit to jlaur/openhab-addons that referenced this issue Jan 27, 2022
fwolter pushed a commit that referenced this issue Jan 28, 2022
* Optimize initialization of shades.

Fixes #12071

Signed-off-by: Jacob Laursen <[email protected]>

* Avoid hashmap reallocation during initialization.

Signed-off-by: Jacob Laursen <[email protected]>
NickWaterton pushed a commit to NickWaterton/openhab-addons that referenced this issue Apr 27, 2022
* Optimize initialization of shades.

Fixes openhab#12071

Signed-off-by: Jacob Laursen <[email protected]>

* Avoid hashmap reallocation during initialization.

Signed-off-by: Jacob Laursen <[email protected]>
Signed-off-by: Nick Waterton <[email protected]>
nemerdaud pushed a commit to nemerdaud/openhab-addons that referenced this issue Jun 29, 2022
* Optimize initialization of shades.

Fixes openhab#12071

Signed-off-by: Jacob Laursen <[email protected]>

* Avoid hashmap reallocation during initialization.

Signed-off-by: Jacob Laursen <[email protected]>
andan67 pushed a commit to andan67/openhab-addons that referenced this issue Nov 6, 2022
* Optimize initialization of shades.

Fixes openhab#12071

Signed-off-by: Jacob Laursen <[email protected]>

* Avoid hashmap reallocation during initialization.

Signed-off-by: Jacob Laursen <[email protected]>
andrasU pushed a commit to andrasU/openhab-addons that referenced this issue Nov 12, 2022
* Optimize initialization of shades.

Fixes openhab#12071

Signed-off-by: Jacob Laursen <[email protected]>

* Avoid hashmap reallocation during initialization.

Signed-off-by: Jacob Laursen <[email protected]>
Signed-off-by: Andras Uhrin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An enhancement or new feature for an existing add-on
Projects
None yet
1 participant