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
65 stars 59 forks source link

Create subclasses for the two Evergy subdomains #9

Closed mark-ignacio closed 1 year ago

mark-ignacio commented 1 year ago

It looks like Evergy uses kcpk for customers in Kansas and kcpl for customers in Missouri.

First commit does a bit of refactoring to separate them into EvergyKS and EvergyMO subclasses of a new __EvergyBase parent class. Second commit hides __evergybase as an option from demo.py:

$ python src/demo.py --error-out-please
usage: demo.py [-h] [--utility {atlanticcityelectric,bge,comed,delmarva,evergyks,evergymo,peco,pepco,pge,pse}] [--username USERNAME] [--password PASSWORD]
               [--aggregate_type {bill,day,hour}] [--start_date START_DATE] [--end_date END_DATE] [--usage_only] [-v]
demo.py: error: unrecognized arguments: --error-out-please

Demo output:

$   python src/demo.py --utility evergymo --verbose
Username: [snip]
Password: 
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

Data for meter: ELEC

Current bill forecast: Forecast(account=Account(customer=Customer(uuid='[snip]'), uuid='[snip]', utility_account_id='[snip]', meter_type=<MeterType.ELEC: 'ELEC'>), start_date=datetime.date(2023, 6, 27), end_date=datetime.date(2023, 7, 26), current_date=datetime.date(2023, 7, 22), unit_of_measure=<UnitOfMeasure.KWH: 'KWH'>, usage_to_date=702.0, cost_to_date=84.0, forecasted_usage=898.0, forecasted_cost=104.0, typical_usage=1073.0, typical_cost=170.0)

Getting historical data: aggregate_type= day start_date= 2023-07-15 18:51:57.167671 end_date= 2023-07-22 18:51:57.167690
DEBUG:/home/mark/sauce/opower/src/opower/opower.py:Fetching: https://kcpl.opower.com/ei/edge/apis/DataBrowser-v1/cws/cost/utilityAccount/[snip]?aggregateType=day&startDate=2023-07-15T00%3A00%3A00-05%3A00&endDate=2023-07-23T00%3A00%3A00-05%3A00
start_time      end_time        consumption     provided_cost   start_minus_prev_end    end_minus_prev_end
2023-07-15 00:00:00-05:00       2023-07-16 00:00:00-05:00       42.879  3.13693458      None    None
2023-07-16 00:00:00-05:00       2023-07-17 00:00:00-05:00       35.7294 2.3988471       0:00:00 1 day, 0:00:00
2023-07-17 00:00:00-05:00       2023-07-18 00:00:00-05:00       41.2188 4.201165002     0:00:00 1 day, 0:00:00
2023-07-18 00:00:00-05:00       2023-07-19 00:00:00-05:00       34.947  3.771765972     0:00:00 1 day, 0:00:00
2023-07-19 00:00:00-05:00       2023-07-20 00:00:00-05:00       40.86   3.956948856     0:00:00 1 day, 0:00:00
2023-07-20 00:00:00-05:00       2023-07-21 00:00:00-05:00       45.2022 4.341655362     0:00:00 1 day, 0:00:00
2023-07-21 00:00:00-05:00       2023-07-22 00:00:00-05:00       40.1844 3.66580365      0:00:00 1 day, 0:00:00
mark-ignacio commented 1 year ago

Will open a replacement PR since it looks like the subclass thing was a bad idea due to downstream class usage and the website loads up the domain using an API call after login - so rewriting to make the existing Evergy class do that instead.