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

Websocket connecting for state changes when screen is turned on even if no widget has been added #2075

Closed
jpelgrom opened this issue Dec 24, 2021 · 4 comments · Fixed by #2079
Labels
bug Something isn't working

Comments

@jpelgrom
Copy link
Member

Home Assistant Android version: 2021.12.3-full (any version >= 2021.12.0)

Android version: 12

Phone model: Google Pixel 4a

Home Assistant version: Core 2021.12.5

Last working Home Assistant release (if known): Any app version < 2021.12.0, before widgets switched to using websocket

Description of problem: When turning on the device, via the broadcast receiver registered for widgets a new websocket connection is established for state changes regardless of whether a widget has actually been added or not. This shouldn't happen and will drain the battery faster if there are no widgets. (Thankfully at least the app stops collecting the flow when the screen is turned off which will end the subscription.)

Traceback (if applicable, to get the logs you may refer to: https://companion.home-assistant.io/docs/troubleshooting/faqs/#android-crash-logs):

The in-app option didn't show me any messages from before starting the app in the foreground, so this was copied from logcat. (I first noticed the issue when working on a PR, and switching to the master branch also showed this, so searching for the same messages at the same times from another app should be the stable version.)

2021-12-24 22:20:03.380 19451-19451/? D/SensorReceiver: Sensor is_interactive corresponding to received event android.intent.action.SCREEN_ON is disabled, skipping sensors update
2021-12-24 22:20:03.381 19451-19451/? D/ButtonWidget: Broadcast received: 
    Broadcast action: android.intent.action.SCREEN_ON
    AppWidgetId: -1
2021-12-24 22:20:03.381 19451-19451/? D/ButtonWidget: Updating all widgets
2021-12-24 22:20:03.387 19451-19451/? D/UrlRepository: localUrl is: true and usesInternalSsid is: true
2021-12-24 22:20:03.389 19451-19451/? D/WebSocketRepository: Sending message number 7: {type=subscribe_events, event_type=state_changed, id=7}
2021-12-24 22:20:03.390 19451-19451/? D/WebSocketRepository: Message number 7 sent
2021-12-24 22:20:03.391 19451-19451/? D/MediaPlayCtrlsWidget: Broadcast received: 
    Broadcast action: android.intent.action.SCREEN_ON
    AppWidgetId: -1
2021-12-24 22:20:03.394 19451-19451/? D/UrlRepository: localUrl is: true and usesInternalSsid is: true
2021-12-24 22:20:03.397 19451-19921/? D/WebSocketRepository: Websocket: onMessage (text)
2021-12-24 22:20:03.398 19451-19921/? D/WebSocketRepository: Message number 7 received: {"id": 7, "type": "result", "success": true, "result": null}
2021-12-24 22:20:03.401 19451-19451/? D/UrlRepository: localUrl is: true and usesInternalSsid is: true
2021-12-24 22:20:08.144 19451-19921/? D/WebSocketRepository: Websocket: onMessage (text)
2021-12-24 22:20:08.155 19451-19921/? D/WebSocketRepository: Message number 7 received: {"id": 7, "type": "event", "event": {"event_type": "state_changed", "data": [removed], "last_changed": "2021-12-24T17:45:10.367883+00:00", "last_updated": "2021-12-24T21:20:08.241326+00:00", "context": {"id": "463c28f6a07feab0cd6f5ba51101f5a8", "parent_id": null, "user_id": null}}}, "origin": "LOCAL", "time_fired": "2021-12-24T21:20:08.241326+00:00", "context": {"id": "463c28f6a07feab0cd6f5ba51101f5a8", "parent_id": null, "user_id": null}}}

Screenshot of problem:

Additional information:

@jpelgrom jpelgrom added the bug Something isn't working label Dec 24, 2021
@dshokouhi
Copy link
Member

For this we just need to add a check to see if we have any widgets stored in the DB before registering for updates

https://github.com/home-assistant/android/blob/master/app/src/main/java/io/homeassistant/companion/android/widgets/BaseWidgetProvider.kt#L78

@jpelgrom
Copy link
Member Author

And some other way to start the flow once a widget has been added, otherwise the state will probably remain static after adding it until the user turns the screen off and on again?

@dshokouhi
Copy link
Member

I thought that was fixed previously

@jpelgrom
Copy link
Member Author

jpelgrom commented Dec 24, 2021

Missed the intent that is fired for widgets that need updates when they're added to trigger the screen on function, so just a check in the database for saved widgets should indeed work.

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

Successfully merging a pull request may close this issue.

2 participants