gcobb321 / icloud3_v3

iCloud3 v3, Development Version - This Repo/Version is used for development and testing of new and updated features. It is not the official release of iCloud3 v3, .
MIT License
169 stars 13 forks source link

18:53:17ICLOUD FAMILY SHARING DEVICES ERROR > • No devices were returned from iCloud Account Family Sharing List, Retry #11 #302

Closed JtwoA closed 3 months ago

JtwoA commented 6 months ago

Just happened to look at my Event Viewer and saw everything except my iPhone with a big red X. Restarted iC3 and looked at the logs. This is the latest version, 3.0.4

18:53:17ICLOUD FAMILY SHARING DEVICES ERROR > 
                • No devices were returned from iCloud Account Family Sharing List, Retry #11

But ahead of that is:

18:53:18PyiCloud Devices >
18:53:18Set PyiCloud Device Id > device_tracker_johns_macbook_pro, DataSource-None, 
               FamShr-(None), FmF-(None)
18:53:17Set PyiCloud Device Id > johnwatchold, DataSource-None, 
               FamShr-(None), FmF-(None)
18:53:17Set PyiCloud Device Id > addison_m, DataSource-None, 
               FamShr-(None), FmF-(None)
18:53:17Set PyiCloud Device Id > bella_m, DataSource-None, 
               FamShr-(None), FmF-(None)
18:53:17Set PyiCloud Device Id > jen_m, DataSource-None, 
               FamShr-(None), FmF-(None)
18:53:17Set PyiCloud Device Id > jaac_5, DataSource-None, 
               FamShr-(None), FmF-(None)
18:53:17Set PyiCloud Device Id > john_mbp, DataSource-None, 
               FamShr-(None), FmF-(None)
18:53:17Set PyiCloud Device Id > johnwatch, DataSource-None, 
               FamShr-(None), FmF-(None)
18:53:17Set PyiCloud Device Id > john_iphone, DataSource-None, 
               FamShr-(None), FmF-(None)

I've reauth'd against Apple twice, successfully, and the devices and people all show normally in FMF.

gcobb321 commented 6 months ago

It's probably a communications issue with Apple servers. It happens to me from time-to-time. An HA restart usually sets up a good connection and everything works again. If it doesn't workd immediately, give it some time. It is not an iCloud3 issue but more of an internet/communication/Apple Server issue.

JtwoA commented 6 months ago

I've updated to the latest HA release and that forced a restart of HA. No change in behaviour. Of note, it's only impacting those devices not running the HA App. My iPhone and my iPad Mini are fine, they're the only two devices running the HA app.

JtwoA commented 6 months ago

Stranger still, after a reboot of iC3 I see this in the event log:

image
gcobb321 commented 6 months ago

I’ve taken a Quick Look at the log file at the iCloud account setup and it keeps coming back with a response code indicating a reauthentication may be needed but the fields in the data do not indicate that it really is needed.

Turn the rawdata log level on again, then go to the Configure > Enter/Request Authentication Code, request a new code, enter the code and restart iCloud3 on the Event Log > Actions. Send me the new Log files if the devices are not available again.

I’ll compare your iCloud data with mine later this morning to see what it’s different.

JtwoA commented 6 months ago

I’ve taken a Quick Look at the log file at the iCloud account setup and it keeps coming back with a response code indicating a reauthentication may be needed but the fields in the data do not indicate that it really is needed.

Turn the rawdata log level on again, then go to the Configure > Enter/Request Authentication Code, request a new code, enter the code and restart iCloud3 on the Event Log > Actions. Send me the new Log files if the devices are not available again.

I’ll compare your iCloud data with mine later this morning to see what it’s different.

I've done as requested. This seems odd to me:

image

This was after receiving and entering the Apple code.

I then noted an HA alert that said "auth required" and RE-auth'd thru Apple a second time (different code). That got rid of the green "needs auth" banner but the devices are still missing.

image
gcobb321 commented 6 months ago

That indicates there were problems setting up the devices with the red X. Send me the the iCloud-0.log. Then restart HA to get a clean log file and send me the new file that will be created where the iCloud access is reinitialized.

Edit: On a reauthentication, the code is sent but the devices are not reloaded again.

gcobb321 commented 6 months ago

iCloud3 starts two processes to connect to the iCloud account and selects the one that gets all the data back first. One starts when iCloud3 is loaded and before anything is done, the second starts in Stage 4 of the iCloud3 setup. This is done to try to have the iCloud account already connected before it is needed to startup faster.

I want to confirm there is not a problem doing this on your system due to timing.

Edit the config/.storage/icloud3/configuration file. Around line 31 is a statement "setup_icloud_session_early": true, Change it to false so it reads "setup_icloud_session_early": false, Save the file. Restart HA.

JtwoA commented 6 months ago

Do you need to see logs at all? Event Log doesn't look any different post-restart,

gcobb321 commented 6 months ago

No. But confirm a few entries in the Event Log.

Right after it starts between the Between the iCloud3 v3.0.4 > Starting and the Stage 1 headers, you should see this: image

There should not be a statement that reads Start iCloud Account Session Executor Job.

And later on, you should see: image

pasch78 commented 6 months ago

I am experiencing the same issue and here's what I have found: Presumably because of iCloud3's activity, Apple keeps locking my AppleID every few days (this never happened to me before and it only started after installing iCloud3). I can easily unlock my AppleID on another device and then I need to reconnect to my AppleID account in iCloud3 including entering a new verification code. So in short: I found a way to fix it, but getting my AppleID account locked is certainly annoying.

JtwoA commented 6 months ago

No. But confirm a few entries in the Event Log.

Right after it starts between the Between the iCloud3 v3.0.4 > Starting and the Stage 1 headers, you should see this: image

There should not be a statement that reads Start iCloud Account Session Executor Job.

And later on, you should see: image

This is what I see @gcobb321:

image image
gcobb321 commented 6 months ago

Here is v3.0.5b1. I've added a verification of the iCloud account access instance selected and a trace that dumps the data returned when the FamShr data is refreshed. Plus a retry reset to see what happens when a refresh is tried 10 times due to no data returned from iCloud,

It also has a new alert that checks when a new version is available on HACS.

Unzip into the icloud3 directory and restart HA. icloud3 v3.0.5b1.zip

EDIT: And have rawdata log level on. Then send me icloud3-0.log

Snuffy2 commented 6 months ago

I believe I'm having the same/similar issue. Let me know if you want me to put this in a separate issue.

I installed v3.0.5b1 as above. Rawdata log at boot: icloud3-3.0.5b1.log

I'm also seeing the 2 errors below in the HA logs: home-assistant_icloud3-3.0.5b1.log

2024-05-13 18:35:25.670 ERROR (MainThread) [custom_components.icloud3] 'last_version'
Traceback (most recent call last):
  File "/config/custom_components/icloud3/support/hacs_ic3.py", line 41, in check_hacs_icloud3_update_available
    version_hacs = hacs_ic3_items[ic3_repo]['last_version']
                   ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
KeyError: 'last_version'
2024-05-13 18:35:28.472 ERROR (MainThread) [homeassistant] Error doing job: Future exception was never retrieved
Traceback (most recent call last):
  File "/config/custom_components/icloud3/support/pyicloud_ic3_interface.py", line 172, in authenticate_icloud_account
    PyiCloud = PyiCloudService(Gb.username, Gb.password,
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/icloud3/support/pyicloud_ic3.py", line 487, in __init__
    self.authenticate()
  File "/config/custom_components/icloud3/support/pyicloud_ic3.py", line 648, in authenticate
    raise PyiCloudFailedLoginException(msg)
custom_components.icloud3.support.pyicloud_ic3.PyiCloudFailedLoginException: Authentication Failed/628, err=421

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/icloud3/support/pyicloud_ic3_interface.py", line 37, in create_PyiCloudService_executor_job
    create_PyiCloudService(Gb.PyiCloudInit, called_from='init')
  File "/config/custom_components/icloud3/support/pyicloud_ic3_interface.py", line 50, in create_PyiCloudService
    authenticate_icloud_account(PyiCloud, called_from=called_from, initial_setup=True)
  File "/config/custom_components/icloud3/support/pyicloud_ic3_interface.py", line 193, in authenticate_icloud_account
    f"Authentication Process, Error-({Gb.PyiCloud.authenticate_method[2:]})")
                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AtributeError: 'NoneType' object has no attribute 'authenticate_method'
gcobb321 commented 6 months ago

@Snuffy2 Let’s keep the problem here

  1. First error has to do with trying to get HACS data from the HACS report file. Easy fix.
  2. second has to do with a reauthentication err=421 indicates one is needed. It should happen automatically or generate reauthentication is needed msg. It might be an error MSG that normally is caught without a message but now caught trying to see what it’s going on.

The icloud3-0.log file has a trace statement when the famshr data is refreshed that dumps everything received to the log file.

Snuffy2 commented 6 months ago

Hopefully this shows what you're looking for. I ran Restart iCloud3 and logs are attached: icloud3-0.log

Let me know if you need me to do something else or send a longer duration of logs.

gcobb321 commented 6 months ago

@Snuffy2 @JtwoA I’m not having this problem (yet) and get data from iCloud , I wonder if the HA iCloud integration is having the same issue. Could you guys install it and see if it is running. You should not need t to do an authentication with the verification code. It uses the same .storage/icloud directory for the cookie session files.

JtwoA commented 6 months ago

Installed the HA Apple iCloud integration. It asked for the confirmation code upon entering creds (and Apple provided it) but upon submitting it I received "Unknown Error".

gcobb321 commented 6 months ago

What is the error in the HA logs?

JtwoA commented 6 months ago

Which log do you need? (At work atm).

gcobb321 commented 6 months ago

The home assistant.log file is probably where the iCloud integration error is would be fine.

Gary Cobb, aka geekstergary


From: John @.> Sent: Tuesday, May 14, 2024 8:30:54 AM To: gcobb321/icloud3_v3 @.> Cc: Gary Cobb @.>; Mention @.> Subject: Re: [gcobb321/icloud3_v3] 18:53:17ICLOUD FAMILY SHARING DEVICES ERROR > • No devices were returned from iCloud Account Family Sharing List, Retry #11 (Issue #302)

Which log do you need? (At work atm).

— Reply to this email directly, view it on GitHubhttps://github.com/gcobb321/icloud3_v3/issues/302#issuecomment-2110090730, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AIOOVBYTRIZBIX5GP4H4I33ZCH7X5AVCNFSM6AAAAABHPK2ZEKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMJQGA4TANZTGA. You are receiving this because you were mentioned.Message ID: @.***>

gcobb321 commented 6 months ago

I found several issues related to the initial iCloud account access.

  1. Errors encountered when the username or password were not valid were not being handled correctly. I do not think this had anything to do with this topic but needed fixing.
  2. When data was not returned from iCloud during the initial FamShr devices setup, the retry routine was checking on the setup status but not actually requesting new data from iCloud. It would use the non-existing data 10 times and then issue the No Devices error.

Code updates are being tested now and v3.0.5b2 should posted here tomorrow.

Snuffy2 commented 6 months ago

Not sure why, how and why I wasn't having issues with anything else. BUT, I went to icloud.com and tried to login with my apple account. It then said my account was locked and I went through the steps to unlock my account.

I then downgraded to 3.0.4 and restarted HA. I re-logged into icloud3 (I had tried a lot of thing so likely logged myself out in the process) and it began to work again.

pasch78 commented 6 months ago

That’s exactly the issue I am experiencing: iCloud account is locked by Apple every few days. After I unlock it and restart HA, everything starts working again. Doesn’t that imply that Apple identifies the connection from iCloud3 as suspicious activity?

gcobb321 commented 6 months ago

I have revamped the iCloud account setup to better support retrying account access during iCloud3 startup. There is also a check to see if the account is locked and appropriate error messages are displayed if it is.

This has not been released. Unzip icloud3 v3.0.5b2 into the iCloud directory and restart HA. icloud3 v3.0.5b2.zip

Change Log - v3.0.5b2 (5/18/2024)

  1. HACS UPUDATE ALERT (New) - The HACS Integration information will be check on a regular basis to see if a newer version of iCloud3 is available.
  2. ICLOUD ACCOUNT AUTHENTICATION/FAMSHR DEVICES LIST (Fixed) - During startup ("Stage 4), the iCloud Account access is set up and the devices in the Family Sharing List is read. If a problem occurred, iCloud3 would retry this 10-times to see if the error was corrected. However, the FamShr data was not being reread and the old data was being used. The FamShr data is now reread correctly when trying to recover from this error.
  3. UPDATE DEVICES SCREEN (Fixed) - When upgrading a device (iPhone, iPad, Watch) and both the old and new devices are still in the Family Sharing List, the new device was being set back to the old device the next time iCloud3 was started.
  4. LOCKED ICLOUD ACCOUNT (New) - An error message is displayed in the HA logs and on the Event Log if the iCloud account is locked.
JtwoA commented 6 months ago

I've installed this and the missing devices are now actively showing. Nicely done, @gcobb321 !

gcobb321 commented 6 months ago

Excellent. I’ll release it.

Snuffy2 commented 6 months ago

icloud3 has been working since I unlocked my account as above. But as an FYI, the HACS update alert shows that version 0.0.0 is available.

2024-05-18_21-49-46 696

gcobb321 commented 6 months ago

I’ll check that and make sure no alerts are generated when it sees 0.0.0.

It is setting the HACS version to 0.0.0 when it finds the .storage/hacs.repositories file and gets a valid icloud3 entry but there is no last_version data element. It is looking for both the icloud3_v3 and icloud3 entry. icloud3_v3 is used when both are there.

My icloud3_v3 entry is:

"394419578": {
      "repository_manifest": {
        "name": "iCloud3 v3, Development Version",
        "homeassistant": "2024.2.0",
        "render_readme": true
      },
      "full_name": "gcobb321/icloud3_v3",
      "authors": [
        "@gcobb321"
      ],
      "category": "integration",
      "description": "iCloud3 v3, Development Version - This Repo/Version is used for development and testing of new and updated features. It is not the official release of iCloud3 v3, .",
      "domain": "icloud3",
      "downloads": 21,
      "etag_repository": "W/\"5f990ca079228bb5b588c08993e9434c7997935d4ca093031d16a444554c6b76\"",
      "last_updated": "2024-05-07T19:09:50Z",
      "stargazers_count": 136,
      "topics": [
        "device-tracker",
        "ha-ios",
        "icloud",
        "icloud-account",
        "tracking",
        "waze",
        "zone",
        "zones"
      ],
      "config_flow": true,
      "default_branch": "main",
      "installed_commit": "25aa65c",
      "installed": true,
      "last_commit": "7d48960",
      "last_version": "v3.0.4",
      "manifest_name": "iCloud3 v3",
      "open_issues": 39,
      "published_tags": [
        "v3.0.4",
        "v3.0.3",
        "v3.0.2a",
        "v3.0.2",
        "v3.0.1.1"
      ],
      "releases": true,
      "version_installed": "v3.0.2a",
      "last_fetched": 1716075749.087158
    }, 

Can you send me your hacs.repositories file so I can see what your looks like?

Snuffy2 commented 6 months ago

Both icloud3 and icloud3_v3 are below.

    "394419578": {
      "repository_manifest": {
        "name": "iCloud3 v3, Development Version",
        "homeassistant": "2024.2.0",
        "render_readme": true
      },
      "full_name": "gcobb321/icloud3_v3",
      "authors": [
        "@gcobb321"
      ],
      "category": "integration",
      "description": "iCloud3 v3, Development Version - This Repo/Version is used for development and testing of new and updated features. It is not the official release of iCloud3 v3, .",
      "domain": "icloud3",
      "downloads": 18,
      "etag_repository": "W/\"8cb981b961284e3731c2efb3416bf325ca5dbf04ce2a42b89325066f72da1b66\"",
      "last_updated": "2024-05-07T19:09:50Z",
      "stargazers_count": 134,
      "topics": [
        "device-tracker",
        "ha-ios",
        "icloud",
        "icloud-account",
        "tracking",
        "waze",
        "zone",
        "zones"
      ],
      "installed_commit": "7d48960",
      "installed": true,
      "last_commit": "7d48960",
      "last_version": "v3.0.4",
      "manifest_name": "iCloud3 v3",
      "releases": true,
      "show_beta": true,
      "version_installed": "v3.0.4",
      "last_fetched": 1715840020.452302
    },
    "222292912": {
      "repository_manifest": {},
      "full_name": "gcobb321/icloud3",
      "category": "integration",
      "description": "iCloud3 v3 - iCloud3 is an advanced iDevice tracker that uses Apple iCloud account and HA Companion App data for presence detection and location based automations.",
      "domain": "icloud3",
      "etag_repository": "W/\"5a08679976aabd03f35823c281ddba5bed9bcbcfeae03bc4a717dfba12d435d6\"",
      "last_updated": "2024-05-15T17:23:12Z",
      "stargazers_count": 487,
      "topics": [
        "device-tracker",
        "ha-ios",
        "icloud",
        "icloud-account",
        "tracking",
        "zone",
        "zones"
      ],
      "last_fetched": 1715797188.097557
    },