Skip to content

Commit

Permalink
fix(api-client): fixed get_account to find the first property that ha…
Browse files Browse the repository at this point in the history
…sn't been moved out of

BREAKING CHANGE:
This change could cause the sensors associated with your meters to change, as they may have been
associated with a property you had moved out of
  • Loading branch information
BottlecapDave committed Nov 10, 2021
1 parent ac02c5f commit 970a7a5
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion custom_components/octopus_energy/api_client.py
Expand Up @@ -21,7 +21,11 @@ async def async_get_account(self, account_id):
data = await response.json(content_type=None)
if ("properties" in data):
# We're only supporting one property at the moment and we don't want to expose addresses
prop = data["properties"][0]
properties = data["properties"]
prop = next(current_prop for current_prop in properties if current_prop["moved_out_at"] == None)
if (prop == None):
raise Exception("Failed to find occupied property")

return {
"electricity_meter_points": prop["electricity_meter_points"],
"gas_meter_points": prop["gas_meter_points"]
Expand Down

0 comments on commit 970a7a5

Please sign in to comment.