pnbruckner / ha-life360

A Home Assistant integration for Life360.
32 stars 4 forks source link

Life360 online (email) entity is constantly updating Connected/Disconnected #22

Closed sirmeili closed 3 weeks ago

sirmeili commented 4 weeks ago

This is more of a question than a bug or issue. Should this entity (Life360 online) be constantly updating every second or so? It just flips back and forth between the 2 states of Connected and Disconnected.

pnbruckner commented 4 weeks ago

No, it shouldn't. What version of the integration are you using?

sirmeili commented 4 weeks ago

Looks like 0.5.0 (from HACS).

This is what I'm seeing in the logbook: image

pnbruckner commented 4 weeks ago

Interesting, it's going off and on line after every update (which happens every 5 seconds.)

There should also be ERRORs in the System Log. Do you see any? If so, please share the details

sirmeili commented 4 weeks ago

I think I found the issue. I had a user that I set up when life360 started not working that was apparently removed from life360 for lack up updates. Even though I removed it from my circle from the app, I think the integration still had it. I just nuked the integration and recreated it and it appears to be fixed. I think this is just an edge case, not something that you probably should code for, but I do have the logs if you want to see them.

pnbruckner commented 4 weeks ago

I'm not sure I followed that, but nothing should be causing the online sensor to be going on and off all the time, except for actual server errors. I would be interested in any details you can share, and/or a description of how I could recreate the same scenario.

sirmeili commented 4 weeks ago

Yeah, so when life360 first started failing months ago, people recommenced setting up a user that did not have the phone verified. I used my Google Voice number to do this. I think at one point life360 removed this user, but it was still in my Circle. I didn't notice this until after I readded 0.5.0.

The relevant logs I was getting were

2024-05-31 11:16:42.170 ERROR (MainThread) [custom_components.life360.coordinator] [REDACTED]: while getting data for Thompson Blend from Family Circle: aiohttp.client_exceptions.ClientResponseError: 404, message='Not Found', url=URL('https://api-cloudfront.life360.com/v3/circles/REDACTED/members/REDACTED'); status: 404 2024-05-31 11:16:42.271 ERROR (MainThread) [custom_components.life360.coordinator] [REDACTED]: Fetching data recovered

Edit: so in this case I think what was happening is expected and was just an issue on my end with a deleted user that was still in my circle

pnbruckner commented 4 weeks ago

Interesting.

So, yeah, if Life360 doesn't see updates from a particular Member's device for a long time, it will set that user as "disconnected." When this happens, the Life360 HA integration will still create a tracker entity for it, but its state will be unknown and its attributes will look like this:

source_type: gps
reason: >-
  Lost Connection: This user has lost connection to Life360. Visit our
  troubleshooting guide to help them reconnect.
attribution: Data provided by life360.com
entity_picture: >-
  https://www.life360.com/img/user_images/b1dc9d38-2982-4782-be36-856908981c78/65d5ee87-46cc-4b12-bb7e-b6b512744eca.jpg?fd=2
friendly_name: Life360 Frederick Test

The above is from a test account I have that is in this exact state. :)

It will also issue a WARNING message in the System Log:

This error originated from a custom integration.

Logger: custom_components.life360.device_tracker
Source: custom_components/life360/device_tracker.py:292
integration: Life360 (documentation, issues)
First occurred: 10:56:22 AM (1 occurrences)
Last logged: 10:56:22 AM

Location data for Life360 Frederick Test (device_tracker.life360_frederick_test) is missing: Lost Connection: This user has lost connection to Life360. Visit our troubleshooting guide to help them reconnect.

Normally I would expect users to disable this HA entity, which will prevent the integration from retrieving data for that Member.

Also, when a Member is removed from a Circle, the HA Life360 integration will eventually see that change and delete its tracker entity, but not until the next time it retrieves the list of Circles & Members and that only happens (normally) when HA restarts. You can force this to happen by reloading the Life360 integration entry. (This is all described in the docs.)

Until that time, if the corresponding HA tracker entity remains enabled, causing the integration to continue to attempt to retrieve its data, it looks like the server will return error 404, "not found". And the current implementation treats that as an unexpected error that indicates the server communications are "down". Of course, when the next Member's data is successfully retrieved, that makes the server look "up" again. This unfortunately repeats every five seconds.

So, yeah, although this shouldn't happen often, it is a valid scenario that I need to take into account. I'll add this to my To Do list.

Thanks for letting me know!

sirmeili commented 4 weeks ago

Thanks for the detailed response. I will say that I removed the user from my circle after the initial signing in with the integration, but I never restarted HA, so maybe that would have fixed it.

I appreciate your work on this and your really fast responses!

pnbruckner commented 4 weeks ago

Restarting HA, reloading the Life360 integration entry, deleting & re-adding it, or disabling the corresponding entity, all would have avoided / worked around the scenario. I wouldn't say it would have "fixed" it. That's something I need to do. lol