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

Sync sensor enabled state with core 2022.6+ #2547

Merged
merged 5 commits into from
May 29, 2022

Conversation

jpelgrom
Copy link
Member

Summary

home-assistant/core#71561 and home-assistant/core#71562 added support for enabling/disabling entities and getting the current state of entities registered by the app, to allow apps and core to stay in sync. This PR implements these features for the sensors in the Android app.

The change should be seamless; when using core <2022.6 nothing changes, starting with core 2022.6 all sensors from the app will be registered with core and changing the enabled state in one place should also change it in another (unless additional permissions are required, in that case you have to enable the sensor in the app).

Screenshots

The only UI for this not in the frontend is the notification the app will post when a sensor is enabled in core, but the app doesn't have the required permissions:
A notification from the Home Assistant app on a phone, title 'Detected Activity' and text 'To enable this sensor, turn it on in the app settings'

Opening the notification links to the specific sensor settings screen.

This also technically works on Wear OS (except for the link to the settings screen), although it will never happen with the existing battery sensors:

A notification from the Home Assistant Wear OS app, title 'Battery Level' and text 'To enable this sensor, turn it on in the app settings'

Link to pull request in Documentation repository

I don't think this is necessary, there is currently no documentation on this behavior and the new behavior matches what is expected / other integrations

Any other notes

Is 1 device with 79 entities a new record for highest number of entities per device?

 - Change sensor 'registered' to indicate not registered, registered as disabled or registered as enabled
 - When a sensor is disabled, set it's status as such on core 2022.6 servers
 - In the sensor registration, use the basic sensor details in case there is no info in the database that can be used
 - Now that there is a standard function to get the version, re-use it
 - Update database migration to reset registration state on db upgrade to make sure the information is correct for all sensors
 - Only sync sensors that are actually available on the device
 - Fix registering all sensors on core <2022.6 on app/core version change
 - Fix unnecessary sensor updates due to location sensors which are never registered always triggering update on core >=2022.6
  - After pushing app enabled changes to core, if on core 2022.6 check if the enabled state for any of the sensors is different from what is registered in the app and try to update the sensors. This is done by reading the entire config, because otherwise we wouldn't know about sensors that have been enabled and the app already updates all sensors at the same time so no need for tracking individual updates in the sensor update response.
  - Restore getting config using webhooks, because only the webhook config contains information about entity enabled state
  - Add support for opening a specific sensor's settings page, used for the notification when trying to enable a sensor that requires granting (additional) permissions
# Conflicts:
#	common/schemas/io.homeassistant.companion.android.database.AppDatabase/27.json
#	common/src/main/java/io/homeassistant/companion/android/database/AppDatabase.kt
@JBassett JBassett merged commit c98b291 into home-assistant:master May 29, 2022
@jpelgrom jpelgrom deleted the sync-sensor-enabled branch May 29, 2022 22:05
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