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

Can't log in to SMUD via HA plugin #97

Closed
lwalkera opened this issue Oct 14, 2024 · 13 comments · Fixed by home-assistant/core#134228
Closed

Can't log in to SMUD via HA plugin #97

lwalkera opened this issue Oct 14, 2024 · 13 comments · Fixed by home-assistant/core#134228

Comments

@lwalkera
Copy link

lwalkera commented Oct 14, 2024

Here is the error:

  File "/srv/homeassistant/lib/python3.12/site-packages/homeassistant/components/opower/config_flow.py", line 50, in _validate_login
    await api.async_login()
  File "/srv/homeassistant/lib/python3.12/site-packages/opower/opower.py", line 199, in async_login
    self.access_token = await self.utility.async_login(
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/srv/homeassistant/lib/python3.12/site-packages/opower/utilities/smud.py", line 294, in async_login
    saml_response = parser2.saml_response
                    ^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'SMUDOktaResponseSamlResponseValueParser' object has no attribute 'saml_response'

@andylittle FYI

@tronikos
Copy link
Owner

@BrianHenryIE could you take a look and fix?

@lwalkera
Copy link
Author

lwalkera commented Oct 16, 2024

Running standalone with -v (403 error maybe?)

DEBUG:opower/utilities/smud.py:Fetching SMUD login page: https://myaccount.smud.org/
DEBUG:opower/utilities/smud.py:Set new cookies: `NSC_~~redacted~~`, `language`, `ASP.NET_SessionId`, `ADRUM_BTa`, `__RequestVerificationToken`
DEBUG:opower/utilities/smud.py:SMUD self verify token: ~~redacted~~ (108 characters)
DEBUG:opower/utilities/smud.py:Performing SMUD login to: https://myaccount.smud.org/
DEBUG:opower/utilities/smud.py:Performed 1 redirects
DEBUG:opower/utilities/smud.py:-> https://myaccount.smud.org/manage/residential
DEBUG:opower/utilities/smud.py:Set new cookies: `ADRUM_BTs`, `ADRUM_BTg`, `ADRUM_BT1`, `.ASPXAUTH`, `ADRUM_BTn`
DEBUG:opower/utilities/smud.py:Opening SMUD energy usage page: https://myaccount.smud.org/manage/opowerresidential/energyusage
DEBUG:opower/utilities/smud.py:Performed 1 redirects
DEBUG:opower/utilities/smud.py:-> https://smud.okta.com/login/sessionCookieRedirect?token=~~redacted~~&redirectUrl=https://smud.okta.com/app/smud_opowerpingfederate_1/~~redacted~~/sso/saml?RelayState=https://smud.opower.com/ei/app/myEnergyUse
DEBUG:opower/utilities/smud.py:Set new cookies: `DT`, `xids`, `sid`, `proximity~~redacted~~`, `JSESSIONID`
DEBUG:opower/utilities/smud.py:Fetching second OKTA login page: https://smud.okta.com/app/smud_opowerpingfederate_1/~~redacted~~/sso/saml?RelayState=https://smud.opower.com/ei/app/myEnergyUse
DEBUG:opower/utilities/smud.py:Parsed SAMLResponse: ~~redacted~~ (10532 characters)
DEBUG:opower/utilities/smud.py:Fetching SMUD ssotransition page: https://myaccount.smud.org/signin/ssotransition
DEBUG:opower/utilities/smud.py:POSTing opower sso page with SAMLResponse: https://idcs-~~redacted~~.identity.oraclecloud.com/fed/v1/sp/sso
DEBUG:opower/utilities/smud.py:Set new cookies: `ORA_OCIS_1`
DEBUG:opower/utilities/smud.py:OCIS_REQ_SP self verify token:~~redacted~~ (727 characters)
DEBUG:opower/utilities/smud.py:POSTing opower sso login page with OCIS_REQ_SP: https://idcs-~~redacted~~.identity.oraclecloud.com/sso/v1/user/login
DEBUG:opower/utilities/smud.py:Performed 7 redirects
DEBUG:opower/utilities/smud.py:-> https://smud.opower.com/ei/app/myEnergyUse
DEBUG:opower/utilities/smud.py:-> https://smud.opower.com/ei/x/energy-use-details
DEBUG:opower/utilities/smud.py:-> https://smud.opower.com/ei/app/api/authenticate?redirectUrl=/x/energy-use-details&failureUrl=/x/error-response-code?error-response-code%3D403&assumeAuthenticatedOnIdP=false
DEBUG:opower/utilities/smud.py:-> https://idcs-~~redacted~~.identity.oraclecloud.com/oauth2/v1/authorize?client_id=Opower_SSO_smud_prod_APPID&response_type=code&scope=openid%20opower_consumer_smud_prodopower_sso&redirect_uri=https://smud.opower.com/ei/app/api/authenticate?sso-type%3DOPEN_ID&state=~~redacted~~&nonce=~~redacted~~
DEBUG:opower/utilities/smud.py:-> https://smud.opower.com/ei/app/api/authenticate?sso-type=OPEN_ID&code=~~redacted~~&state=~~redacted~~
DEBUG:opower/utilities/smud.py:-> https://smud.opower.com/ei/app/api/authenticate?sso-type=OPEN_ID
DEBUG:opower/utilities/smud.py:-> https://smud.opower.com/ei/app/api/authenticate?redirectUrl=/x/energy-use-details&failureUrl=/x/error-response-code?error-response-code=403&assumeAuthenticatedOnIdP=false
DEBUG:opower/utilities/smud.py:Set new cookies: `~~redacted~~`, `JSESSIONID-samesite`, `JSESSIONID`, `~~redacted~~`
DEBUG:opower/utilities/smud.py:Fetching okta saml page with SAMLRequest, RelayState: https://smud.opower.com/ei/x/energy-use-details
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "opower/__main__.py", line 214, in <module>
    asyncio.run(_main())
  File "/usr/lib/python3.12/asyncio/runners.py", line 194, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/asyncio/base_events.py", line 687, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "opower/__main__.py", line 93, in _main
    await opower.async_login()
  File "opower/opower.py", line 199, in async_login
    self.access_token = await self.utility.async_login(
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "opower/utilities/smud.py", line 294, in async_login
    saml_response = parser2.saml_response
                    ^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'SMUDOktaResponseSamlResponseValueParser' object has no attribute 'saml_response'

@lwalkera
Copy link
Author

lwalkera commented Nov 2, 2024

@BrianHenryIE bump

@lwalkera
Copy link
Author

@BrianHenryIE @andylittle @tronikos Bump

@philipathomas
Copy link

bump bump bump

@jonthewise
Copy link

I am having this same problem.

@andylittle
Copy link
Contributor

This is working from the command line. I've been testing the SMUD integration and found that the dropdown menu for selecting meter numbers is gone. That might have broken the integration. I'll create a pull request once I've done more testing. Any help testing would be appreciated.
Can someone without solar post a screenshot of the first energy usage page?
image

@kquinsland
Copy link

Any help testing would be appreciated.

What do you need help testing, specifically?


image

@andylittle
Copy link
Contributor

Grab the changed file from my repository and get it into your HA install if you can. It is running in mine now and it seems to work. My HA is in a docker container so I just edited the file in there. You only have to delete some lines.

Make sure not to break your HA.

@kquinsland
Copy link

kquinsland commented Dec 28, 2024

Grab the changed file from my repository and get it into your HA install if you can.

For anybody else following along @ home, the delta can be seen here:

main...andylittle:opower-smud:smud-login-fix

In container (for version 2024.11; the path will change based on the version of HA you're on. See: this issue), the file to change is /usr/local/lib/python3.12/site-packages/opower/utilities/smud.py


And yeah, that seems to have worked for me:

2024-12-28 16:12:40.597 INFO (SyncWorker_21) [homeassistant.loader] Loaded opower from homeassistant.components.opower
2024-12-28 16:13:14.335 INFO (MainThread) [homeassistant.setup] Setting up opower
2024-12-28 16:13:31.992 INFO (MainThread) [homeassistant.components.sensor] Setting up opower.sensor
2024-12-28 16:13:31.993 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new sensor.opower entity: sensor.current_bill_electric_usage_to_date
2024-12-28 16:13:31.994 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new sensor.opower entity: sensor.current_bill_electric_forecasted_usage
2024-12-28 16:13:31.994 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new sensor.opower entity: sensor.typical_monthly_electric_usage
2024-12-28 16:13:31.995 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new sensor.opower entity: sensor.current_bill_electric_cost_to_date
2024-12-28 16:13:31.996 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new sensor.opower entity: sensor.current_bill_electric_forecasted_cost
2024-12-28 16:13:31.996 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new sensor.opower entity: sensor.typical_monthly_electric_cost
2024-12-28 16:13:31.997 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new sensor.opower entity: sensor.current_bill_electric_start_date
2024-12-28 16:13:31.997 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new sensor.opower entity: sensor.current_bill_electric_end_date

I am running HA in k8s so this change won't stick / the next time the pod is re-scheduled, it'll be gone. We'll find out if the changes are only needed on setup or each time the integration is spun up for auth.

@jonthewise
Copy link

I can't seem to even find the path to this file in my HA install - I'm just using a RasPi5 with HA OS installed. Added the SSH add-in, and I'm on the terminal, but I can't seem to find the file. Hopefully it gets committed soon and I can just update the plugin

@jonthewise
Copy link

Figured it out... https://developers.home-assistant.io/docs/operating-system/debugging/

Gotta make sure you scroll to the bottom and run the command to drop into the container's bash before you can find the file.

Then make sure you restart home assistant after you change the file. After that SMUD login worked. Thank you!

@BrianHenryIE
Copy link
Contributor

Testing the @andylittle change using python src/demo.py --utility smud --username [email protected] --password "mypassword" -v solves the issue for me. I.e. previously I get the no attribute 'saml_response' as in the above report, and after I get the table of energy use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants