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

Wait for astral to have attribute 'location' before using it #185

Closed
wants to merge 1 commit into from

Conversation

ullebe1
Copy link

@ullebe1 ullebe1 commented Feb 3, 2022

Sometimes while initializing the component the astral module doesn't have the location attribute yet when the component tries to use it, cause bugs like #148, #149 and #175.

This PR implements a loop that causes initialization to wait another second if the attribute isn't available yet. If it still isn't available after 30 seconds we let the initialization continue and crash, like before.

I have been running with a simpler version of the fix (a single 10 second sleep) for months, which has completely fixed the issue for me, but this version is a bit more clever to avoid waiting longer than necessary while also being more resilient in case longer is needed.

Closes #149, closes #175.

@amaisano
Copy link

Same problem. Please merge! The patch fixes the issue for me.

@claytonjn
Copy link
Owner

claytonjn commented Mar 11, 2022

I'd feel better if this used asyncio.sleep, and unless I'm missing something location = astral.location.Location() should be within the while loop. <- looked at it too quickly, ignore.

Also, is there a similar problem with the location = astral.Location() call in the except block? If memory serves me right, this call is for astral 1.x.

@ullebe1
Copy link
Author

ullebe1 commented Apr 20, 2022

I'd feel better if this used asyncio.sleep

The component is currently not async, so would it make sense to mix async into without converting the whole thing?
Also, made a quick test with it using asyncio.sleep, but when using that the fix didn't work anymore - perhaps because of the above?

Also, is there a similar problem with the location = astral.Location() call in the except block? If memory serves me right, this call is for astral 1.x.

It looks like it isn't present in 2.x as their docs point to astral.location.Location().

@claytonjn
Copy link
Owner

I actually have an async version running locally and will push that out as a new beta release as soon as I get a chance. That being said, I don't think this is required after #189 and using the homeassistant helper is likely a better solution.

@ullebe1 @amaisano can you confirm if 2.0.8-beta fixes this issue for you?

@ullebe1
Copy link
Author

ullebe1 commented Apr 20, 2022

@claytonjn 2.0.8-beta fixes it for me, great if we don't need this workaround anyway. I'll continue testing over the next days and report back.

Also a future async version sounds awesome - thank you!

@ullebe1
Copy link
Author

ullebe1 commented May 4, 2022

@claytonjn I just wanted to report back that after testing the 2.0.8-beta for the last two weeks it works great and completely solved the issue.

@claytonjn
Copy link
Owner

I've pushed this to the main branch and have the async code in the dev (beta) branch, so will close this.

@claytonjn claytonjn closed this May 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Setup Issues 2021.5.0
3 participants