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
53 stars 49 forks source link

Add service point id as field for Account to distinguish multiple meters #65

Closed c0mputerguru closed 5 months ago

c0mputerguru commented 5 months ago

I'm adding a service point id to be able to distinguish between multiple meters on a single account id. The use case is that I have 2 electric accounts when making the get customers API call; the first is consumption from the grid, and the second is my solar production. I'd like to be able to distinguish between the 2 of them, and while uuid can do it, I'd prefer to have something that is a little more human friendly. Ultimately I want to be able to pull both in as separate statistics in home assistant.

I have tested these changes on my personal account, and the Account field gets updated correctly for historical usage. I cannot test the forecasts as my provider (PSE) does not have forecasts.

All precommits have been run and pass.

My list of accounts looks like the following:

...
            "utilityAccounts": [
                {
                    "id": 3232041,
                    "uuid": "1f231471-d223-11e3-ba8c-1b40f3043709",
                    "utilityAccountId": "4000542376",
                    "utilityAccountId2": null,
                    "servicePointId": 373123,
                    "meterType": "ELEC",
                    "preferredUtilityAccountId": "4000542376",
                    "readResolution": "QUARTER_HOUR"
                },
                {
                    "id": 6729658,
                    "uuid": "699c98e6-b860-11e8-8151-1661d329c91b",
                    "utilityAccountId": "4000542376",
                    "utilityAccountId2": null,
                    "servicePointId": 2134661,
                    "meterType": "ELEC",
                    "preferredUtilityAccountId": "4000542376",
                    "readResolution": "QUARTER_HOUR"
                },
                {
                    "id": 3212155,
                    "uuid": "1f04a9f9-d223-11e3-ba8c-1b40f3043709",
                    "utilityAccountId": "4000542390",
                    "utilityAccountId2": null,
                    "servicePointId": 201726,
                    "meterType": "GAS",
                    "preferredUtilityAccountId": "4000542390",
                    "readResolution": "QUARTER_HOUR"
                }
            ]
...
c0mputerguru commented 5 months ago

Given that you're also the owner for the home assistant integration, I'm curious on whether you'd prefer to add this, and then add the service point id as a part of the home assistant id prefix (https://github.com/home-assistant/core/blob/a385ca93bd0d5b7de4b8b20fe7cc34c006ab1aed/homeassistant/components/opower/coordinator.py#L99) or whether to bite the bullet and just use the uuid. Either will be a breaking change for folks given the name of the entity changes, but the uuid change should be the last case of it breaking.

Unfortunately I can't seem to find any documentation on the APIs to determine whether the utility account + service point id + meter type is unique enough, so the safest thing to do would be to use the uuid, but uuid's aren't very readable.

tronikos commented 5 months ago

Closing since this isn't needed after https://github.com/home-assistant/core/pull/108616