Skip to content

Startup Error: NotAuthorizedException / Invalid login token (Token expired) during initialization #173

@madbrain76

Description

@madbrain76

Startup Error: NotAuthorizedException / Invalid login token (Token expired) during initialization

Description

During Home Assistant startup, the Winix custom integration logs a continuous stack trace due to an expired AWS Cognito login token during the initialization handshake (GetId operation). Despite this initial failure, functionality recovers and works properly afterward. The integration should gracefully catch this specific token expiration exception, suppress the full traceback, and attempt a clean token refresh/re-authentication during startup.

Expected Behavior

The integration should handle expired tokens gracefully during initialization by renewing the login token silently or raising a concise warning instead of dumping a full NotAuthorizedException traceback into the logs.

Actual Behavior

The following traceback is generated once during every startup sequence:

This error originated from a custom integration.

Logger: custom_components.winix
Source: custom_components/winix/manager.py:131
Integration: Winix (documentation, issues)
First occurred: 17:07:55 (1 occurrence)
Last logged: 17:07:55

Failed to get identity_id: Failed to get Cognito Identity ID: An error occurred (NotAuthorizedException) when calling the GetId operation: Invalid login token. Token expired: 1778976175 >= 1778927108
Traceback (most recent call last):
File "/config/custom_components/winix/helpers.py", line 228, in get_identity_id_sync
response = _COGNITO_IDENTITY_CLIENT.get_id(
IdentityPoolId=_COGNITO_IDENTITY_POOL_ID,
Logins={login_key: id_token},
)
File "/usr/local/lib/python3.14/site-packages/botocore/client.py", line 606, in _api_call
return self._make_api_call(operation_name, kwargs)
~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.14/site-packages/botocore/context.py", line 123, in wrapper
return func(*args, **kwargs)
File "/usr/local/lib/python3.14/site-packages/botocore/client.py", line 1094, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.errorfactory.NotAuthorizedException: An error occurred (NotAuthorizedException) when calling the GetId operation: Invalid login token. Token expired: 1778976175 >= 1778927108

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/config/custom_components/winix/manager.py", line 131, in prepare_devices_wrappers
identity_id = await self.hass.async_add_executor_job(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Helpers.get_identity_id_sync, id_tok
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/usr/local/lib/python3.14/concurrent/futures/thread.py", line 86, in run
result = ctx.run(self.task)
File "/usr/local/lib/python3.14/concurrent/futures/thread.py", line 73, in run
return fn(*args, **kwargs)
File "/config/custom_components/winix/helpers.py", line 238, in get_identity_id_sync
raise WinixException(
...<4 lines>...
) from err
custom_components.winix.helpers.WinixException: Failed to get Cognito Identity ID: An error occurred (NotAuthorizedException) when calling the GetId operation: Invalid login token. Token expired: 1778976175 >= 1778927108

Environment

  • Home Assistant Core: Python 3.14 environment
  • Integration: Winix Custom Component

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions