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

Cannot authenticate with blueair server #55

Closed
spikeygg opened this issue Dec 13, 2023 · 23 comments
Closed

Cannot authenticate with blueair server #55

spikeygg opened this issue Dec 13, 2023 · 23 comments
Assignees
Labels
bug Something isn't working

Comments

@spikeygg
Copy link

I'm trying to get the integration to authenticate but it keeps erroring out. I've updated my password with blueair via a "password reset" and a normal "change password" both times I synced it up in the integration but it is continues to report "invalid password".

First it reports this:

Uncaught error from Chrome WebView 119.0.6045.193 on Android 13 TypeError: Cannot read properties of undefined (reading 'friendly_name') friendly_name (src/common/entity/compute_state_name.ts:8:13) entityId (src/data/history.ts:318:6) computeGroupKey (src/data/history.ts:481:8) computeHistory (src/data/history.ts:431:28) this.hass!, (src/panels/lovelace/cards/hui-history-graph-card.ts:118:10) callbackFunction (src/data/history.ts:259:17) callback (node_modules/home-assistant-js-websocket/dist/connection.js:23:33) forEach (node_modules/home-assistant-js-websocket/dist/connection.js:15:25)

After trying a few times it then returns this:

Error setting up entry XXXXXXXXXXXXX for ha_blueair
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 402, in async_setup
    result = await component.async_setup_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/ha_blueair/__init__.py", line 72, in async_setup_entry
    _, devices = await get_devices(
                 ^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/blueair_api/util_bootstrap.py", line 27, in get_devices
    api_devices = await api.get_devices()
                  ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/blueair_api/http_blueair.py", line 116, in get_devices
    "X-AUTH-TOKEN": await self.get_auth_token(),
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/blueair_api/http_blueair.py", line 42, in get_auth_token
    self.auth_token = await self._get_auth_token()
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/blueair_api/http_blueair.py", line 100, in _get_auth_token
    raise LoginError("invalid password")
blueair_api.errors.LoginError: invalid password

This is with debug logging enabled.

@spikeygg
Copy link
Author

More detail.

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/blueair_api/http_aws_blueair.py", line 16, in request_with_active_session_wrapper
    return await func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/blueair_api/http_aws_blueair.py", line 164, in devices
    "Authorization": f"Bearer {await self.get_access_token()}",
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/blueair_api/http_aws_blueair.py", line 156, in get_access_token
    await self.refresh_access_token()
  File "/usr/local/lib/python3.11/site-packages/blueair_api/http_aws_blueair.py", line 146, in refresh_access_token
    await self._post_request_with_logging_and_errors_raised(
  File "/usr/local/lib/python3.11/site-packages/blueair_api/http_aws_blueair.py", line 53, in request_with_errors_wrapper
    raise SessionError(response_text)
blueair_api.errors.SessionError: {"message":"Token invalid or Request Timeout"}

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 402, in async_setup
    result = await component.async_setup_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/ha_blueair/__init__.py", line 75, in async_setup_entry
    _, aws_devices = await get_aws_devices(
                     ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/blueair_api/util_bootstrap.py", line 56, in get_aws_devices
    api_devices = await api.devices()
                  ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/blueair_api/http_aws_blueair.py", line 24, in request_with_active_session_wrapper
    response = await func(*args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/blueair_api/http_aws_blueair.py", line 164, in devices
    "Authorization": f"Bearer {await self.get_access_token()}",
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/blueair_api/http_aws_blueair.py", line 156, in get_access_token
    await self.refresh_access_token()
  File "/usr/local/lib/python3.11/site-packages/blueair_api/http_aws_blueair.py", line 146, in refresh_access_token
    await self._post_request_with_logging_and_errors_raised(
  File "/usr/local/lib/python3.11/site-packages/blueair_api/http_aws_blueair.py", line 53, in request_with_errors_wrapper
    raise SessionError(response_text)
blueair_api.errors.SessionError: {"message":"Token invalid or Request Timeout"}

Getting invalid tokens or request timeout messages.

@dahlb
Copy link
Owner

dahlb commented Dec 14, 2023

the error you have in the stack isn't about passwords, it is about timeouts. maybe you have a firewall blocking your traffic?

@spikeygg
Copy link
Author

it is about timeouts.

A couple of things to mention here.

  1. I was just using the aijayadams blueair integration component previously. It worked well since September 2021 until yesterday when I uninstalled it. I did have some warnings about the wrong units being used for the entities but other than that it was working! Yesterday, when looking closer at it, I saw that his repo had been removed from HACS. Since it was no longer maintained and I saw yours which seemed to be maintained I attempted the transition. After uninstalling the old one and installing this new one I now see this error consistently.
  2. Per your comment, I tried pulling up my live firewall logs while reloading the integration to force it to attempt to make the connection. I didn't see anything getting blocked by my firewall. Does your integration use a specifically different port to authenticate? My Home Assistant hardware should have access to the internet with which to connect and authenticate. I guess I'm not sure what else I can check on my end.

Do you have any other ideas of things I can try to figure it out?

@msbjr88
Copy link

msbjr88 commented Dec 17, 2023

I'm getting the same error. It was working great until we had a power outage this morning and now am seeing this.

Logger: homeassistant.config_entries
Source: config_entries.py:402
First occurred: 11:04:17 AM (1 occurrences)
Last logged: 11:04:17 AM
Error setting up entry {my email} for ha_blueair

Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/config_entries.py", line 402, in async_setup
result = await component.async_setup_entry(hass, self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/ha_blueair/init.py", line 72, in async_setup_entry
_, devices = await get_devices(
^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/blueair_api/util_bootstrap.py", line 27, in get_devices
api_devices = await api.get_devices()
^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/blueair_api/http_blueair.py", line 116, in get_devices
"X-AUTH-TOKEN": await self.get_auth_token(),
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/blueair_api/http_blueair.py", line 42, in get_auth_token
self.auth_token = await self._get_auth_token()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/blueair_api/http_blueair.py", line 100, in _get_auth_token
raise LoginError("invalid password")
blueair_api.errors.LoginError: invalid password

@dahlb dahlb self-assigned this Dec 21, 2023
@dahlb dahlb added the bug Something isn't working label Dec 21, 2023
@dahlb
Copy link
Owner

dahlb commented Dec 21, 2023

I've finally started to see this too, but it is intermittent so might take a few days to track down

@msbjr88
Copy link

msbjr88 commented Dec 21, 2023 via email

@spikeygg
Copy link
Author

spikeygg commented Dec 21, 2023

Don’t know if it would be helpful but the only way I get it to resolve after a reboot is to disable and then re enable the integration.

My integration installation has never succeeded. I just tried the disable/re-enable method and it still doesn't seem to authenticate properly.

@dahlb
Copy link
Owner

dahlb commented Dec 21, 2023

I think the blue air servers are just overwhelmed and often time out, every time you reload or disable/re-enable the integration just tries again, sometimes retrieving an auth token completes those methods are just allowing it to retry. I doubt we can fix this, I'll try to look into more graceful retry methods in ha but hopefully blue fixes their servers soon

@dahlb
Copy link
Owner

dahlb commented Dec 21, 2023

1.8.0 should wrap the error in a way that allows home assistant to gracefully retry to expo backoff etc when the login server times out

based on what I observed in while developing this fix my guess is the pool of api servers has one broken server without a health check so it isn't being removed from the pool even though it is broken. I assume blueair will fix this but no idea when, but 1.8.0 should manage the symptoms until then.

@msbjr88
Copy link

msbjr88 commented Dec 21, 2023 via email

@dahlb
Copy link
Owner

dahlb commented Dec 21, 2023

can confirm the retry is working in 1.8.0 took ha 5 tries on my setup but no intervention was required at least

@spikeygg
Copy link
Author

I've updated to the 1.8.0 and restarted HA but I'm still getting the "Failed setup, will retry" message.

It's pretty strange, I've deleted and reloaded the integration a couple of times and it takes my username and password at the initial prompt (saying success!) but then fails to complete the setup and doesn't create any entities. I've tried entering a bad username or password and it doesn't let the initial prompt go away so I know it's taking my credentials appropriately but then fails to succeed subsequently.

@dahlb
Copy link
Owner

dahlb commented Dec 21, 2023

"Failed setup, will retry" is the new message 1.8.0 allows, don't reload/delete etc just let it keep trying until their server works once you have a token it seems the rest of the endpoints aren't having this issue; though if you delete and then try to re-add you will have to manually keep trying if you get a bad login server while attempting to login/setup the integration for the first time

@spikeygg
Copy link
Author

"Failed setup, will retry" is the new message 1.8.0 allows, don't reload/delete etc just let it keep trying until their server works once you have a token it seems the rest of the endpoints aren't having this issue; though if you delete and then try to re-add you will have to manually keep trying if you get a bad login server while attempting to login/setup the integration for the first time

what if it never succeeds?

@dahlb
Copy link
Owner

dahlb commented Dec 21, 2023

@spikeygg then you have very bad luck or you haven't let it try enough; or you have a different error but that seems less likely

@spikeygg
Copy link
Author

spikeygg commented Dec 21, 2023

@spikeygg then you have very bad luck or you haven't let it try enough; or you have a different error but that seems less likely

maybe you can have it report how many times it has tried? I think it's trying and failing repeatedly because something isn't right. I'm leaving it to go and retry and it isn't succeeding.

@dahlb
Copy link
Owner

dahlb commented Dec 21, 2023

you can watch it retry either counting what's in the logs or just have the integration page on your ha instance up; :8123/config/integrations/integration/ha_blueair on the integration page you can watch the status changing from intializing to failed and back again

@spikeygg
Copy link
Author

you can watch it retry either counting what's in the logs or just have the integration page on your ha instance up; :8123/config/integrations/integration/ha_blueair on the integration page you can watch the status changing from intializing to failed and back again

with the debug logging enabled, nothing is reported to the home assistant logs.

@dahlb
Copy link
Owner

dahlb commented Dec 21, 2023

1.8.1 adds extra logging when it has to retry, ha has built in logging described https://developers.home-assistant.io/docs/integration_setup_failures/ referencing ConfigEntryNotReady but for convenience there is no harm in extra logging :)

@spikeygg
Copy link
Author

spikeygg commented Dec 21, 2023

So reviewing the debug logs, it looks like my login is succeeding eventually (six retries) and the debug log says it is creating the entities but, apparently, that isn't making its way back to the integration/HA because the entities don't show up in the devices and I don't see the entities in my list. I'd post my debug log but it looks like there is a lot of sensitive information in it... is there some way to send it to you securely?

@spikeygg
Copy link
Author

Ah ha! With your debug version I was able to see that the 'brightness' json entry didn't exist for one of my purifiers (likely because I turned it completely off, to zero on their app). This was causing problems with the integration.

I went into their app and set the brightness on all devices to something non-zero... after doing that the integration worked! I still think there's a bug in the integration because it can't handle a non-existent 'brightness' value but at least I'm operational now. 👍

@dahlb
Copy link
Owner

dahlb commented Dec 22, 2023

@spikeygg 1.8.4 should gracefully handle missing brightness values

@spikeygg
Copy link
Author

Thanks for the support!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants