tronikos / opower

A Python library for getting historical and forecasted usage/cost from utilities that use opower.com such as PG&E
Apache License 2.0
54 stars 49 forks source link

autodetect Evergy opower subdomain #11

Closed mark-ignacio closed 11 months ago

mark-ignacio commented 11 months ago

Detects the Evergy subdomain by hitting an API after logging in.

This also emits a debug log about the detected subdomain, as well as a warning level log when it sees a subdomain that Evergy is not known to use (which would probably only happen if it expands to a different state?).

$ python src/demo.py --utility evergy -v
Username: [snip]
Password: 
DEBUG:/home/mark/sauce/opower/src/opower/utilities/evergy.py:detected Evergy subdomain: kcpl
DEBUG:/home/mark/sauce/opower/src/opower/opower.py:Fetching: https://kcpl.opower.com/ei/edge/apis/multi-account-v1/cws/kcpl/customers?offset=0&batchSize=100&addressFilter=
DEBUG:/home/mark/sauce/opower/src/opower/opower.py:Fetching: https://kcpl.opower.com/ei/edge/apis/bill-forecast-cws-v1/cws/kcpl/customers/[snip]/combined-forecast
[...]

closes #10

tronikos commented 11 months ago

Could you please take a look at my most recent refactoring? I tried to address an issue that Home Assistant doesn't like modifying default headers since the same session is used across different integrations but it looks like I broke Evergy and likely other utilities. My utility is PG&E that is the only one not using access token. See some details in https://github.com/home-assistant/core/issues/97655#issuecomment-1663209206

tronikos commented 11 months ago

Never mind. The issue was fixed in https://github.com/tronikos/opower/commit/e8d88d315829169789270b1eaf8bcd78342306d3

akoebbe commented 11 months ago

@mark-ignacio Thanks for catching this and coding the fix. I had no idea that's why the subdomain wasn't kcpl for me (on the KS side).