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

Support for Evergy (KS, MO) #6

Closed akoebbe closed 1 year ago

akoebbe commented 1 year ago

This adds support for Evergy which serves the Kansas City metro area (KS, MO) and surrounding areas.

akoebbe commented 1 year ago

For the record, here is the output of the demo command...

$ python src/demo.py --utility kcpk --username [redacted] --password [redacted] --verbose
DEBUG:/home/andrew/Projects/opower/src/opower/opower.py:Fetching: https://kcpk.opower.com/ei/edge/apis/multi-account-v1/cws/kcpk/customers?offset=0&batchSize=100&addressFilter=
DEBUG:/home/andrew/Projects/opower/src/opower/opower.py:Fetching: https://kcpk.opower.com/ei/edge/apis/bill-forecast-cws-v1/cws/kcpk/customers/[redacted]/combined-forecast

Data for meter: ELEC

Current bill forecast: Forecast(account=Account(customer=Customer(uuid='[redacted]'), uuid='[redacted]', utility_account_id='[redacted]', meter_type=<MeterType.ELEC: 'ELEC'>), start_date=datetime.date(2023, 6, 13), end_date=datetime.date(2023, 7, 12), current_date=datetime.date(2023, 7, 13), unit_of_measure=<UnitOfMeasure.KWH: 'KWH'>, usage_to_date=1902.0, cost_to_date=266.0, forecasted_usage=1967.0, forecasted_cost=275.0, typical_usage=1552.0, typical_cost=244.0)

Getting historical data: aggregate_type= day start_date= 2023-07-05 23:06:03.706354 end_date= 2023-07-12 23:06:03.706381
DEBUG:/home/andrew/Projects/opower/src/opower/opower.py:Fetching: https://kcpk.opower.com/ei/edge/apis/DataBrowser-v1/cws/cost/utilityAccount/[redacted]?aggregateType=day&startDate=2023-07-05T00%3A00%3A00-05%3A00&endDate=2023-07-13T00%3A00%3A00-05%3A00
start_time      end_time        consumption     provided_cost   start_minus_prev_end    end_minus_prev_end
2023-07-05 00:00:00-05:00       2023-07-06 00:00:00-05:00       65.5722 7.001143794     None    None
2023-07-06 00:00:00-05:00       2023-07-07 00:00:00-05:00       64.0794 6.841757538     0:00:00 1 day, 0:00:00
2023-07-07 00:00:00-05:00       2023-07-08 00:00:00-05:00       62.6478 6.688905606     0:00:00 1 day, 0:00:00
2023-07-08 00:00:00-05:00       2023-07-09 00:00:00-05:00       53.241  5.68454157      0:00:00 1 day, 0:00:00
2023-07-09 00:00:00-05:00       2023-07-10 00:00:00-05:00       55.3848 5.913435096     0:00:00 1 day, 0:00:00
2023-07-10 00:00:00-05:00       2023-07-11 00:00:00-05:00       57.3732 6.125736564     0:00:00 1 day, 0:00:00
2023-07-11 00:00:00-05:00       2023-07-12 00:00:00-05:00       79.4022 8.477772894     0:00:00 1 day, 0:00:00
tronikos commented 1 year ago

Can you also pump the version in pyproject.toml and update the README.md?

akoebbe commented 1 year ago

Good catch. README.md and version updated.

akoebbe commented 1 year ago

Sorry I missed pushing my previous pending comments.

No worries. Addressing things now.

tronikos commented 1 year ago

I tried running with:

python src/demo.py --utility=kcpk --username=test --password=test -v

and I got:

  File "C:\Users\user\Documents\GitHub\opower\src\opower\utilities\evergy.py", line 75, in async_login
    if resp.headers["location"] != "/ma/my-account/account-summary":
       ~~~~~~~~~~~~^^^^^^^^^^^^
KeyError: 'location'

Can you please fix before I make a new release? Make sure you sync because I made a couple small changes.

akoebbe commented 1 year ago

Oh wow. It's a different response if the username and password are incorrect than if the login verification token is wrong. TIL. Working on it now.

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