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

[Bug]: No a need to stop heartbeat due to one timeout #236

Closed
3 tasks
Lurker00 opened this issue May 16, 2024 · 3 comments
Closed
3 tasks

[Bug]: No a need to stop heartbeat due to one timeout #236

Lurker00 opened this issue May 16, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@Lurker00
Copy link

LocalTuya Version

2024.5.0b1

Home Assistant Version

2024.5.3

Environment

  • Does the device work using the Home Assistant Tuya Cloud component?
  • Is this device connected to another local integration, including Home Assistant and any other tools?
  • The devices are within the same HA subnet, and they get discovered automatically when I add them

What happened?

I suggest to replace these lines:

while self.heartbeater:
try:
await self.subdevices_query()
await asyncio.sleep(HEARTBEAT_SUB_DEVICES_INTERVAL)
except (Exception, asyncio.CancelledError) as ex:
self.debug(f"Sub-devices heartbeat stopped due to: {ex}")
break

with

            wait = 0
            while self.heartbeater:
                try:
                    await asyncio.sleep(HEARTBEAT_SUB_DEVICES_INTERVAL)
                    await self.subdevices_query()
                    wait = 0
                except TimeoutError:
                    wait += 1
                    self.debug(f"Sub-devices heartbeat failed due to timeout {wait} times", force=True)
                    if wait >= 5:
                        break
                except (Exception, asyncio.CancelledError) as ex:
                    self.debug(f"Sub-devices heartbeat stopped due to: {ex}", force=True)
                    break

This is running in my HA server. I didn't see more than 1 time of failures in a row. With the version with the sleep after the query (i.e. no a delay after the timeout), once I saw 3 times, and never more.

I've changed the order of lines 922 and 923 based on your suggestion in #227, and to make a delay after a timeout with minimum changes.

Steps to reproduce.

Don't know.

Relevant log output

2024-05-16 09:55:57.426 WARNING (MainThread) [custom_components.localtuya.core.pytuya] [bf8...m91] Sub-devices heartbeat failed due to timeout 1 times

Diagnostics information.

No response

@Lurker00 Lurker00 added the bug Something isn't working label May 16, 2024
@xZetsubou
Copy link
Owner

This has been changed and handled, but I haven't pushed it yet.

@Lurker00
Copy link
Author

Just in case, it is worth to make a similar change in start_heartbeat. A gateway may be just busy with other tasks.

@xZetsubou xZetsubou added the master/next-release Fixed in master branch, Will be ready in the next release label May 18, 2024
Copy link

This issue was closed because it was resolved on the release:

@github-actions github-actions bot added stale and removed master/next-release Fixed in master branch, Will be ready in the next release stale labels May 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants