From 970a7a58bdb00504b2c922d6e0a4632e71d9a17f Mon Sep 17 00:00:00 2001 From: BottlecapDave Date: Wed, 10 Nov 2021 19:31:23 +0000 Subject: [PATCH] fix(api-client): fixed get_account to find the first property that hasn'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 --- custom_components/octopus_energy/api_client.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/custom_components/octopus_energy/api_client.py b/custom_components/octopus_energy/api_client.py index b2c7b7c0..9ed5b973 100644 --- a/custom_components/octopus_energy/api_client.py +++ b/custom_components/octopus_energy/api_client.py @@ -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"]