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

Improve Wear OS error handling on home, check websocket connection state #2261

Merged
merged 5 commits into from Feb 19, 2022

Conversation

jpelgrom
Copy link
Member

Summary

This PR improves the Wear OS' app error handling on the home screen, by showing errors and/or redirecting to onboarding instead of crashing the app on errors. More specifically:

  • Handle network/server errors gracefully and show an error + retry button
  • The websocket state is monitored and used to require logging in again if authentication permanently fails
  • Fixes the app getting stuck on a loading screen if none of the entities on the server are in a supported domain

For more on specific changes, view the comments in individual commits.

Screenshots

General error:
App showing 'Error loading entities' with a 'Retry' button

If the user has favorites, the error will be shown below the favorites (in place of the loading text/chip) and favorites are still accessible:
App showing a favorite at the top of the screen, and below that 'Error loading entities' with a 'Retry' button

No supported domains message if loading completed but the lists are still emtpy:
App showing an error 'No Supported Entities, Check the documentation for more information'

Settings remains accessible in all cases to allow changing tile settings, logging out, etc.

If you need to login again because authentication failed, the app will immediately send you to onboarding like the phone app.

Link to pull request in Documentation repository

I don't think this is needed, "Check the documentation" in the no supported domains error refers to the general documentation for Wear OS which lists supported domains.

Any other notes

If you're going to test this, be aware that because the websocket doesn't immediately throw an error if something fails once the connection is established, the app might send multiple requests before stopping which can trigger maximum number of failed login -> IP ban protections.

 - Switch the job used for monitoring whether a connection has been established to use Deferred, which will allow us to get the exception that caused the job to be cancelled (and also makes the code a little easier)
 - Add a variable to the websocket repository to monitor the state of the connection. This will allow the app to respond to handled exceptions.
 - If multiple outgoing messages are pending before the connection is opened, if we receive an invalid auth message or onFailure callback this will be processed last. The connected job is still 'completed', so it shouldn't return true but return if it was successful. This will ensure that any messages after the first one that triggered the failure, will be ignored until the job is reset.
 - Set the connection state to authenticating before sending the message, to make sure that we don't accidentally override a very quick response
 - Add a state for the loading progress to the view model in order to be able to update the home view with errors if necessary
 - If loading the main data failed because of authentication, reset the session like in the phone app and send the user back to onboarding
 - Fix the app getting stuck on a loading screen, even if everything loaded correctly, if there are no supported entity domains in the response
Copy link
Collaborator

@JBassett JBassett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just needs to fix a merge conflict.

# Conflicts:
#	common/src/main/res/values/strings.xml
#	wear/src/main/java/io/homeassistant/companion/android/home/MainViewModel.kt
@JBassett JBassett merged commit 83bdcfd into home-assistant:master Feb 19, 2022
@jpelgrom jpelgrom deleted the wear-error-handling branch February 19, 2022 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants