ha-emporia-vue icon indicating copy to clipboard operation
ha-emporia-vue copied to clipboard

Adding integration stuck on menu

Open fasavard opened this issue 3 years ago • 27 comments

image

When adding the integration, i get stuck on the looping animation of the lower right in the menu. Nothing else happend.

I have put the home assistant log on debug but nothing gets logs, should i look somewhere else ?

fasavard avatar Dec 29 '21 23:12 fasavard

Have have been debugging for a while. Right now i have found that any username or password (even a bad one) will not work

Also, i got a very weird behavior where i already had my account, but after i let the process hang for a while, i got an email from emporia to congratulate me aboute creating my new account

fasavard avatar Dec 30 '21 12:12 fasavard

Adding the integration from my phone finally five my an error, `Logger: custom_components.emporia_vue.config_flow Source: custom_components/emporia_vue/config_flow.py:38 Integration: Emporia Vue (documentation) First occurred: 08:10:16 (1 occurrences) Last logged: 08:10:16

Unexpected exception Traceback (most recent call last): File "/config/custom_components/emporia_vue/config_flow.py", line 77, in async_step_user info = await validate_input(self.hass, user_input) File "/config/custom_components/emporia_vue/config_flow.py", line 48, in validate_input if not await hub.authenticate(data[CONF_EMAIL], data[CONF_PASSWORD]): File "/config/custom_components/emporia_vue/config_flow.py", line 38, in authenticate result = await loop.run_in_executor(None, self.vue.login, username, password) File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run result = self.fn(*self.args, **self.kwargs) File "/usr/local/lib/python3.9/site-packages/pyemvue/pyemvue.py", line 184, in login self.auth = Auth( File "/usr/local/lib/python3.9/site-packages/pyemvue/auth.py", line 45, in init self.cognito.authenticate(password=password) File "/usr/local/lib/python3.9/site-packages/pycognito/init.py", line 447, in authenticate tokens = aws.authenticate_user() File "/usr/local/lib/python3.9/site-packages/pycognito/aws_srp.py", line 249, in authenticate_user response = boto_client.initiate_auth( File "/usr/local/lib/python3.9/site-packages/botocore/client.py", line 357, in _api_call return self._make_api_call(operation_name, kwargs) File "/usr/local/lib/python3.9/site-packages/botocore/client.py", line 676, in _make_api_call raise error_class(parsed_response, operation_name) botocore.errorfactory.UserNotFoundException: An error occurred (UserNotFoundException) when calling the InitiateAuth operation: User does not exist.`

I can confirm the user does exist. Could it be some caracter support problem ? The email have dots in it ie: [email protected]

fasavard avatar Dec 30 '21 13:12 fasavard

I wouldn't expect the dots to be a problem. What region are you in? Right now it only tries to authenticate against the east us cognito user pool but I don't know if they have added additional ones for different regions or if everyone uses the same pool. If you're outside of the US then that could be the problem.

magico13 avatar Dec 30 '21 13:12 magico13

Hi, yes im in quebec Canada so that might explain the issue

fasavard avatar Dec 30 '21 13:12 fasavard

Ok, I wonder if they have a separate user pool then. If so then your user wouldn't exist in the one it's trying to authenticate against. I'm not as familiar with the AWS data centers outside of the US. If you want to try to figure out where your account is, capture the network traffic in your browser when logging into the Emporia web view and look for requests with cognito in the url. https://web.emporiaenergy.com/#/

I can get you more specific steps later if you want/need them.

magico13 avatar Dec 30 '21 13:12 magico13

image I am on east-2, is it the same as the one you are using ?

fasavard avatar Dec 30 '21 13:12 fasavard

Hmm, yes that's the same so that's not the issue. On one hand that's good because there's quite a bit of work to make it support different regions but on the other hand that means I'm not sure what the issue is. Would you be willing to run a python script that uses the library that this integration is based on? That would let us remove the Home Assistant layer to hopefully see whether it's an issue with the library or the integration, you'd just need to use pip to get the required dependencies.

magico13 avatar Dec 30 '21 14:12 magico13

If you're willing to try running the script, I just tested this one with my own account. You'll need to pip install pyemvue to install the library (which is this one if you're interested: https://github.com/magico13/pyemvue) and then put the following into a new .py file and run it.

from pyemvue import PyEmVue

email = input('Enter email: ')
password = input('Enter password: ')

print('Attempting to log in...')
vue = PyEmVue()
vue.login(username=email, password=password)

details = vue.get_customer_details(email)
print(f'Successful. Your customer id is {details.customer_gid}')

If it can log in then it should print out your customer id, which is something that can only be requested from the server so we know it works. If it can't then it'll throw an exception and print out the whole stack trace. I tested with my own credentials and some made up ones and it worked for mine.

magico13 avatar Dec 30 '21 15:12 magico13

Yes of course, Just a fyi on running on a blue if that changes anything https://www.home-assistant.io/blue/

fasavard avatar Dec 30 '21 15:12 fasavard

So im not sure yet how to run it on the blue but i runned it on my pc and got this:

vue.login(username=email, password=password) Traceback (most recent call last): File "", line 1, in File "C:\Users\fasavard\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pyemvue\pyemvue.py", line 184, in login self.auth = Auth( File "C:\Users\fasavard\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pyemvue\auth.py", line 47, in init self.tokens = self.refresh_tokens() File "C:\Users\fasavard\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\pyemvue\auth.py", line 51, in refresh_tokens self.cognito.renew_access_token() AttributeError: 'Auth' object has no attribute 'cognito'

fasavard avatar Dec 30 '21 15:12 fasavard

That's interesting and unexpected. I think the only way that could happen is if python didn't treat the username and/or password as "truthy". The section of code that defines the cognito variable in that class either requires existing tokens or the username and password to be set. We should be hitting this line of code here to set that: https://github.com/magico13/PyEmVue/blob/master/pyemvue/auth.py#L43

Since you posted your email earlier I can try to check if it doesn't like something about that. If it's something with your password then you might try changing it to something else?

magico13 avatar Dec 30 '21 15:12 magico13

yes of course, i will try a simple one right now

fasavard avatar Dec 30 '21 15:12 fasavard

so i just try a very simple password and the error

fasavard avatar Dec 30 '21 15:12 fasavard

so i just try a very simple password and the error

I think part of your reply might have been dropped. Did the error go away or is it still happening?

magico13 avatar Dec 30 '21 15:12 magico13

so i see in the class we have a user, passe, and email, Are we suppose to provide an email aswell ? image

ho yes sorry about the message before, the problem is still there

fasavard avatar Dec 30 '21 15:12 fasavard

Oh, there might have been some confusion. Don't enter the email and password into the file, those are just prompts and you should enter them on the command line when it comes up. If you want to just hard code them into the file instead of entering them when running it then replace those lines with

email = '[email protected]'
password = 'yourpassword'

I think the way you have it right now you're probably just pressing enter when those prompts come up so it isn't actually passing in the email or password, just empty strings.

magico13 avatar Dec 30 '21 15:12 magico13

ho right my bad ! it is working: :/Users/fasavard/test.py Attempting to log in... Successful. Your customer id is 49506 PS C:\Users\fasavard>

fasavard avatar Dec 30 '21 15:12 fasavard

Awesome, that's a good sign. You said that you tried making the password simpler? Does the Home Assistant integration log in correctly with that new password?

magico13 avatar Dec 30 '21 15:12 magico13

ok now i got this:

This error originated from a custom integration.

Logger: custom_components.emporia_vue Source: custom_components/emporia_vue/init.py:263 Integration: Emporia Vue (documentation) First occurred: 10:57:19 (2 occurrences) Last logged: 10:58:19

Error communicating with Emporia API: No channels found during update for scale 1MIN

I will try a reset of my device just in case

fasavard avatar Dec 30 '21 16:12 fasavard

AFter reboot, it still hang but got those 2 error that i havent seen:

Logger: homeassistant.components.hassio.handler Source: components/hassio/handler.py:230 Integration: Home Assistant Supervisor (documentation, issues) First occurred: 11:03:30 (4 occurrences) Last logged: 11:03:30

/ingress/validate_session return code 401

Logger: homeassistant.components.hassio Source: components/hassio/websocket_api.py:119 Integration: Home Assistant Supervisor (documentation, issues) First occurred: 11:03:30 (4 occurrences) Last logged: 11:03:30

Failed to to call /ingress/validate_session -

not sure how they would be related though

fasavard avatar Dec 30 '21 16:12 fasavard

It looks like you were able to log in at least. Sometimes their API is finicky and doesn't return all the data when it's requested and if that happens during set up it can cause some issues. As long as the initial set up is ok you'll see an occasional issue during updates where data doesn't come back but the next update a minute later usually resolves that.

Do you see any of the different "channels" as separate devices with the minute, day, and month sensors on them?

image

image

magico13 avatar Dec 30 '21 16:12 magico13

no unfortunatly, still stuck on the menu where it ask for my email and password. Would you like to do a google meet ? maybe it would help ? https://meet.google.com/cke-hqzj-zkt?pli=1

fasavard avatar Dec 30 '21 16:12 fasavard

image

After closing the infinit loop windows i got this with this log: This error originated from a custom integration.

Logger: custom_components.emporia_vue.config_flow Source: config_entries.py:1211 Integration: Emporia Vue (documentation) First occurred: 11:19:06 (1 occurrences) Last logged: 11:19:06

Unexpected exception Traceback (most recent call last): File "/config/custom_components/emporia_vue/config_flow.py", line 80, in async_step_user self._abort_if_unique_id_configured() File "/usr/src/homeassistant/homeassistant/config_entries.py", line 1211, in _abort_if_unique_id_configured raise data_entry_flow.AbortFlow("already_configured") homeassistant.data_entry_flow.AbortFlow: Flow aborted: already_configured

fasavard avatar Dec 30 '21 16:12 fasavard

I can't hop on a call at the moment (technically am at work and already in a meeting) but I might be able to this afternoon/evening. My email is [email protected] if you want to send me a meeting invite for some time after 2pm eastern.

magico13 avatar Dec 30 '21 16:12 magico13

awesome thanks will do and i will continu to debug

fasavard avatar Dec 30 '21 16:12 fasavard

Sooo it started working out but i havent done anything :O

fasavard avatar Dec 30 '21 18:12 fasavard

That last error message did say "already configured" so a reboot might have let it finish setup. I'm not sure if the initial problem was related to the password, I've seen special characters in passwords cause some problems in the past with other software, but hopefully it stays working now.

It will reauthenticate with the stored username and password each boot so if you change your password you'll have to remove and readd the integration with the new password, but all the devices and entities should repopulate in-place so you shouldn't mess up any custom displays by doing that.

Maybe monitor it for a day and if it stays working (especially through a reboot) then I think we should be safe to close this. Sound good?

magico13 avatar Dec 30 '21 18:12 magico13

Since this issue have been fixe i will close the issus

fasavard avatar Dec 05 '22 11:12 fasavard