gcobb321 / icloud3

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.
MIT License
545 stars 54 forks source link

Cannot update iCloud credentials after password change #301

Closed pheisiph closed 2 months ago

pheisiph commented 7 months ago

Home Assistant

Core 2024.1.6 Supervisor 2024.01.1 Operating System 11.5 Frontend 20240104.0

iCloud3 3.0.rc9

I had to change my iCloud password, which included signing out of all devices. Obviously that broke the iCloud3 integration with Home Assistant. I tried to update the account username/password through the HA integration, but selecting "ICLOUD ACCOUNT & IOS APP" returns an "Unknown Error Occurred" message. Logs reveal "UnboundLocalError: cannot access local variable 'logged_into_msg' where it is not associated with a value"

removing and re-adding the iCloud3 integration through HACS did not help, even with restarts. It seems like the integration is retaining the outdated credentials somewhere, even when the integration itself has been removed.

image

image

(logs in the details below)

Error message from the logs "Error Handling Request" `/usr/local/lib/python3.11/site-packages/aiohttp/web_protocol.py:421` ``` Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/aiohttp/web_protocol.py", line 452, in _handle_request resp = await request_handler(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/aiohttp/web_app.py", line 543, in _handle resp = await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/aiohttp/web_middlewares.py", line 114, in impl return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 85, in security_filter_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 100, in forwarded_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 28, in request_context_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 80, in ban_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 233, in auth_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/headers.py", line 31, in headers_middleware response = await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 149, in handle result = await handler(request, **request.match_info) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/decorators.py", line 63, in with_admin return await func(self, request, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 234, in post return await super().post(request, flow_id) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 72, in wrapper result = await method(view, request, data, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 110, in post result = await self._flow_mgr.async_configure(flow_id, data) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 320, in async_configure result = await self._async_handle_step( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 416, in _async_handle_step result: FlowResult = await getattr(flow, method)(user_input) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/icloud3/config_flow.py", line 963, in async_step_menu return await self.async_step_icloud_account() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/icloud3/config_flow.py", line 2217, in async_step_icloud_account data_schema=self.form_schema(self.step_id), ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/icloud3/config_flow.py", line 4191, in form_schema self._set_action_list_item_username_password() File "/config/custom_components/icloud3/config_flow.py", line 2472, in _set_action_list_item_username_password self.actions_list[LOGGED_INTO_MSG_ACTION_LIST_IDX].replace('^msg', logged_into_msg) ^^^^^^^^^^^^^^^ UnboundLocalError: cannot access local variable 'logged_into_msg' where it is not associated with a value ```
Error message from the logs "cannot access local variable 'logged_into_msg' where it is not associated with a value" `custom_components/icloud3/config_flow.py:2472` ``` cannot access local variable 'logged_into_msg' where it is not associated with a value Traceback (most recent call last): File "/config/custom_components/icloud3/config_flow.py", line 2120, in async_step_icloud_account data_schema=self.form_schema(self.step_id), ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/icloud3/config_flow.py", line 4191, in form_schema self._set_action_list_item_username_password() File "/config/custom_components/icloud3/config_flow.py", line 2472, in _set_action_list_item_username_password self.actions_list[LOGGED_INTO_MSG_ACTION_LIST_IDX].replace('^msg', logged_into_msg) ^^^^^^^^^^^^^^^ UnboundLocalError: cannot access local variable 'logged_into_msg' where it is not associated with a value ```
Excerpt from the "Full Logs" ``` 2024-02-06 12:14:09.414 ERROR (SyncWorker_6) [icloud3] * iCloud3 Error > An error occurred logging into the iCloud Account. Authentication Process/Error-Password) 2024-02-06 12:14:09.420 ERROR (SyncWorker_2) [icloud3] * iCloud3 Error > An error occurred logging into the iCloud Account. Authentication Process/Error-Password, ERROR-Invalid username/password) 2024-02-06 12:14:09.426 ERROR (SyncWorker_2) [icloud3] 'NoneType' object has no attribute 'authenticate_method' Traceback (most recent call last): File "/config/custom_components/icloud3/support/pyicloud_ic3_interface.py", line 159, in authenticate_icloud_account PyiCloud = PyiCloudService(Gb.username, Gb.password, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/icloud3/support/pyicloud_ic3.py", line 481, in __init__ self.authenticate() File "/config/custom_components/icloud3/support/pyicloud_ic3.py", line 629, in authenticate raise PyiCloudFailedLoginException(msg) custom_components.icloud3.support.pyicloud_ic3.PyiCloudFailedLoginException: Login Error, Invalid username/password)/609, err=421 During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/config/custom_components/icloud3/support/start_ic3_control.py", line 195, in stage_4_setup_data_sources pyicloud_ic3_interface.create_PyiCloudService(Gb.PyiCloudInit, called_from='stage4') File "/config/custom_components/icloud3/support/pyicloud_ic3_interface.py", line 52, 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 181, in authenticate_icloud_account if instr(Gb.PyiCloud.authenticate_method, 'Invalid username/password'): ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'NoneType' object has no attribute 'authenticate_method' 2024-02-06 12:14:12.502 WARNING (MainThread) [aiohomekit.controller.coap.pdu] Transaction 0 failed with error 6 (Invalid request 2024-02-06 12:14:17.501 WARNING (MainThread) [aiohomekit.controller.coap.pdu] Transaction 0 failed with error 6 (Invalid request 2024-02-06 12:18:05.545 ERROR (MainThread) [icloud3] cannot access local variable 'logged_into_msg' where it is not associated with a value ```

Edit/Update: I was able to resolve this by deleting /root/config/.storage/icloud3/configuration and ./restore_state, which allowed my to restart the configuration from scratch.

gcobb321 commented 7 months ago

I have just uploaded v3.0.rc10.2 to the iCloud3 Releases page.

The icloud3.zip file is available for immediate download (unzip into the icloud3 directory and restart HA) or it should show up on HACS within 2-days. It fixes this, I believe, and other items. There are also additional features you may find interesting.

The Releases page and full change log are here

6ixfalls commented 7 months ago

@gcobb321, this doesn't seem to be fixed in v3.0.rc10.2. With a new install, I encountered this error after restarting after a configuration change. I'm installing through HACS, and I can confirm the version shown is v3.0.rc10.2 in the configuration menu.

gcobb321 commented 7 months ago

That has been fixed in rc10.3 that I uploaded several hours ago. You can get it immediately by going to the GitHub releases page and downloading the icloud3.zip file or waiting for HACS to do the update tonight. You may also be able to refresh HACS by going to it, selecting the 3-dots in the upper right corner and refreshing the information.