From 28250d83f2e71688fa3154f77a15afe4688697a0 Mon Sep 17 00:00:00 2001 From: ramonsca Date: Sun, 18 Feb 2024 00:37:10 +0100 Subject: [PATCH] Discard supply points without power --- custom_components/pvpc_energy/ufd.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/custom_components/pvpc_energy/ufd.py b/custom_components/pvpc_energy/ufd.py index bbba147..8dda0a4 100644 --- a/custom_components/pvpc_energy/ufd.py +++ b/custom_components/pvpc_energy/ufd.py @@ -160,10 +160,13 @@ async def supplypoints(): if resp.status == 200: response = await resp.json() _LOGGER.debug(f"response={response}") - UFD.cups = response['supplyPoints']['items'][0]['cups'] - UFD.power_high = float(response['supplyPoints']['items'][0]['power1']) - UFD.power_low = float(response['supplyPoints']['items'][0]['power2']) - UFD.zip_code = response['supplyPoints']['items'][0]['address']['zipCode'] - _LOGGER.debug(f"cups={UFD.cups}, power_high={UFD.power_high}, power_low={UFD.power_low}") + for supplyPoint in response['supplyPoints']['items']: + if supplyPoint['power1'] != '' and supplyPoint['power1'] != '': + UFD.cups = supplyPoint['cups'] + UFD.power_high = float(supplyPoint['power1']) + UFD.power_low = float(supplyPoint['power2']) + UFD.zip_code = supplyPoint['address']['zipCode'] + _LOGGER.debug(f"cups={UFD.cups}, power_high={UFD.power_high}, power_low={UFD.power_low}") + break _LOGGER.debug(f"END - UFD.supplypoints()") \ No newline at end of file