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

Fix legacy bridge poll timeout issues #35

Merged
merged 2 commits into from
May 3, 2024
Merged

Conversation

andersevenrud
Copy link
Owner

@andersevenrud andersevenrud commented Mar 29, 2024

Hopefully this fixes the timeout issues users have been reporting by creating another poll implementation for legacy bridges.

Overview

Changes only applies to legacy devices

  • Only the first poll (aka "discovery") actually requests values from all nodes
  • All the nodes are polled sequentially instead of concurrently
  • All subsequent polls only fetches metadata
  • The first poll has its own timeout value (and configuration)
  • A failsafe was added if for some reason values are missing from data

Potential downsides

  • If a node value poll fails, the entity will not get any values in HA until an update from websocket comes in (or the integration is restarted and the poll succeeds this time)
    • This does get logged as an error
  • If the websocket connection goes down and never reconnects for some reason, HA will get out of sync until restarted

@andersevenrud andersevenrud added investigation Needs investigation 1.6.x Bridge 1 (Legacy) labels Apr 2, 2024
@andersevenrud andersevenrud changed the title Possible solutions for legacy timeouts Fix legacy bridge poll timeout issues Apr 2, 2024
@sonite
Copy link
Contributor

sonite commented May 2, 2024

Adding this two file changes to v1.5.1 does not make it better. It does not run through the nodes.

2024-05-02 21:39:25.654 WARNING (SyncWorker_1) [homeassistant.loader] We found a custom integration hacs which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
2024-05-02 21:39:25.655 WARNING (SyncWorker_1) [homeassistant.loader] We found a custom integration nordpool which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
2024-05-02 21:39:25.655 WARNING (SyncWorker_1) [homeassistant.loader] We found a custom integration nexa_bridge_x which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
2024-05-02 21:39:27.945 WARNING (MainThread) [homeassistant.helpers.frame] Detected that custom integration 'hacs' accesses hass.components.frontend. This is deprecated and will stop working in Home Assistant 2024.9, it should be updated to import functions used from frontend directly at custom_components/hacs/frontend.py, line 68: hass.components.frontend.async_register_built_in_panel(, please create a bug report at https://github.com/hacs/integration/issues
2024-05-02 21:39:29.010 WARNING (MainThread) [homeassistant.helpers.frame] Detected that custom integration 'hacs' accesses hass.helpers.event. This is deprecated and will stop working in Home Assistant 2024.11, it should be updated to import functions used from event directly at custom_components/hacs/base.py, line 642: self.hass.helpers.event.async_track_time_interval(, please create a bug report at https://github.com/hacs/integration/issues
2024-05-02 21:40:48.334 ERROR (MainThread) [custom_components.nexa_bridge_x.nexa] Unexpected error fetching Nexa Bridge X Coordinator data
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 315, in _async_refresh
    self.data = await self._async_update_data()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/nexa_bridge_x/nexa.py", line 672, in _async_update_data
    results = await asyncio.gather(*[
              ^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/nexa_bridge_x/nexa.py", line 347, in fetch_nodes
    async for r in result:
TypeError: 'async for' requires an object with __aiter__ method, got list
2024-05-02 21:40:53.862 ERROR (MainThread) [custom_components.nexa_bridge_x.nexa] Unexpected error fetching Nexa Bridge X Coordinator data
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 315, in _async_refresh
    self.data = await self._async_update_data()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/nexa_bridge_x/nexa.py", line 672, in _async_update_data
    results = await asyncio.gather(*[
              ^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/nexa_bridge_x/nexa.py", line 347, in fetch_nodes
    async for r in result:
TypeError: 'async for' requires an object with __aiter__ method, got list
2024-05-02 21:41:04.439 ERROR (MainThread) [custom_components.nexa_bridge_x.nexa] Unexpected error fetching Nexa Bridge X Coordinator data
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 315, in _async_refresh
    self.data = await self._async_update_data()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/nexa_bridge_x/nexa.py", line 672, in _async_update_data
    results = await asyncio.gather(*[
              ^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/nexa_bridge_x/nexa.py", line 347, in fetch_nodes
    async for r in result:
TypeError: 'async for' requires an object with __aiter__ method, got list
2024-05-02 21:41:06.897 ERROR (MainThread) [custom_components.nexa_bridge_x.nexa] Unexpected error fetching Nexa Bridge X Coordinator data
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 315, in _async_refresh
    self.data = await self._async_update_data()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/nexa_bridge_x/nexa.py", line 672, in _async_update_data
    results = await asyncio.gather(*[
              ^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/nexa_bridge_x/nexa.py", line 347, in fetch_nodes
    async for r in result:
TypeError: 'async for' requires an object with __aiter__ method, got list
2024-05-02 21:41:12.770 ERROR (MainThread) [custom_components.nexa_bridge_x.nexa] Unexpected error fetching Nexa Bridge X Coordinator data
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 315, in _async_refresh
    self.data = await self._async_update_data()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/nexa_bridge_x/nexa.py", line 672, in _async_update_data
    results = await asyncio.gather(*[
              ^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/nexa_bridge_x/nexa.py", line 347, in fetch_nodes
    async for r in result:
TypeError: 'async for' requires an object with __aiter__ method, got list
2024-05-02 21:41:23.573 ERROR (MainThread) [custom_components.nexa_bridge_x.nexa] Unexpected error fetching Nexa Bridge X Coordinator data
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 315, in _async_refresh
    self.data = await self._async_update_data()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/nexa_bridge_x/nexa.py", line 672, in _async_update_data
    results = await asyncio.gather(*[
              ^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/nexa_bridge_x/nexa.py", line 347, in fetch_nodes
    async for r in result:
TypeError: 'async for' requires an object with __aiter__ method, got list
2024-05-02 21:41:25.044 ERROR (MainThread) [custom_components.nexa_bridge_x.nexa] Unexpected error fetching Nexa Bridge X Coordinator data
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 315, in _async_refresh
    self.data = await self._async_update_data()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/nexa_bridge_x/nexa.py", line 672, in _async_update_data
    results = await asyncio.gather(*[
              ^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/nexa_bridge_x/nexa.py", line 347, in fetch_nodes
    async for r in result:
TypeError: 'async for' requires an object with __aiter__ method, got list
2024-05-02 21:42:05.765 ERROR (MainThread) [custom_components.nexa_bridge_x.nexa] Unexpected error fetching Nexa Bridge X Coordinator data
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 315, in _async_refresh
    self.data = await self._async_update_data()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/nexa_bridge_x/nexa.py", line 672, in _async_update_data
    results = await asyncio.gather(*[
              ^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/nexa_bridge_x/nexa.py", line 347, in fetch_nodes
    async for r in result:
TypeError: 'async for' requires an object with __aiter__ method, got list
2024-05-02 21:42:47.414 DEBUG (MainThread) [custom_components.nexa_bridge_x.nexa] GET http://192.168.1.122/v1/info: null
2024-05-02 21:42:47.591 DEBUG (MainThread) [custom_components.nexa_bridge_x.nexa] GET http://192.168.1.122/v1/info: 200
2024-05-02 21:42:47.592 DEBUG (MainThread) [custom_components.nexa_bridge_x.nexa] GET http://192.168.1.122/v1/info: null
2024-05-02 21:42:47.593 DEBUG (MainThread) [custom_components.nexa_bridge_x.nexa] GET http://192.168.1.122/v1/nodes: null
2024-05-02 21:42:47.594 DEBUG (MainThread) [custom_components.nexa_bridge_x.nexa] GET http://192.168.1.122/v1/energy: null
2024-05-02 21:42:47.831 DEBUG (MainThread) [custom_components.nexa_bridge_x.nexa] GET http://192.168.1.122/v1/nodes: 200
2024-05-02 21:42:47.832 ERROR (MainThread) [custom_components.nexa_bridge_x.nexa] Unexpected error fetching Nexa Bridge X Coordinator data
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 315, in _async_refresh
    self.data = await self._async_update_data()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/nexa_bridge_x/nexa.py", line 672, in _async_update_data
    results = await asyncio.gather(*[
              ^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/nexa_bridge_x/nexa.py", line 347, in fetch_nodes
    async for r in result:
TypeError: 'async for' requires an object with __aiter__ method, got list
2024-05-02 21:42:47.832 DEBUG (MainThread) [custom_components.nexa_bridge_x.nexa] Finished fetching Nexa Bridge X Coordinator data in 0.241 seconds (success: False)
2024-05-02 21:42:47.835 DEBUG (MainThread) [custom_components.nexa_bridge_x.nexa] GET http://192.168.1.122/v1/energy: 200
2024-05-02 21:42:47.887 DEBUG (MainThread) [custom_components.nexa_bridge_x.nexa] GET http://192.168.1.122/v1/info: 200
2024-05-02 21:42:53.301 DEBUG (MainThread) [custom_components.nexa_bridge_x.nexa] GET http://192.168.1.122/v1/info: null
2024-05-02 21:42:53.455 DEBUG (MainThread) [custom_components.nexa_bridge_x.nexa] GET http://192.168.1.122/v1/info: 200
2024-05-02 21:42:53.456 DEBUG (MainThread) [custom_components.nexa_bridge_x.nexa] GET http://192.168.1.122/v1/info: null
2024-05-02 21:42:53.457 DEBUG (MainThread) [custom_components.nexa_bridge_x.nexa] GET http://192.168.1.122/v1/nodes: null
2024-05-02 21:42:53.458 DEBUG (MainThread) [custom_components.nexa_bridge_x.nexa] GET http://192.168.1.122/v1/energy: null
2024-05-02 21:42:53.651 DEBUG (MainThread) [custom_components.nexa_bridge_x.nexa] GET http://192.168.1.122/v1/nodes: 200
2024-05-02 21:42:53.652 ERROR (MainThread) [custom_components.nexa_bridge_x.nexa] Unexpected error fetching Nexa Bridge X Coordinator data
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 315, in _async_refresh
    self.data = await self._async_update_data()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/nexa_bridge_x/nexa.py", line 672, in _async_update_data
    results = await asyncio.gather(*[
              ^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/nexa_bridge_x/nexa.py", line 347, in fetch_nodes
    async for r in result:
TypeError: 'async for' requires an object with __aiter__ method, got list
2024-05-02 21:42:53.653 DEBUG (MainThread) [custom_components.nexa_bridge_x.nexa] Finished fetching Nexa Bridge X Coordinator data in 0.197 seconds (success: False)
2024-05-02 21:42:53.655 DEBUG (MainThread) [custom_components.nexa_bridge_x.nexa] GET http://192.168.1.122/v1/energy: 200
2024-05-02 21:42:53.715 DEBUG (MainThread) [custom_components.nexa_bridge_x.nexa] GET http://192.168.1.122/v1/info: 200

@andersevenrud
Copy link
Owner Author

I've pushed an additional change to this PR that might take care of that TypeError: 'async for' requires an object with __aiter__ method, got list which is the underlying cause of this error.

Getting a bit late here, and I don't have my Nexa running atm, so didn't have a chance to actually test this change. I must have messed up when I tried this myself last time we talked...

Ref: a4e2ba1

@andersevenrud
Copy link
Owner Author

Glad to hear that it worked (a4e2ba1#commitcomment-141638719)!

I'll merge this and create a new release :)

@andersevenrud andersevenrud merged commit 3f0af19 into main May 3, 2024
3 checks passed
@andersevenrud andersevenrud deleted the try/legacy-fix branch May 3, 2024 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.6.x Bridge 1 (Legacy) investigation Needs investigation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

My Nexa Bridge (not X) won't find any devices Legacy Nexa Bridge Connectivity Issues
2 participants