Skip to content

Commit

Permalink
fix(api-client): Added more checks for when meters have no agreements
Browse files Browse the repository at this point in the history
  • Loading branch information
BottlecapDave committed Apr 1, 2023
1 parent 5898f41 commit ee86fe0
Showing 1 changed file with 36 additions and 20 deletions.
56 changes: 36 additions & 20 deletions custom_components/octopus_energy/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,17 +176,25 @@ async def async_get_account(self, account_id):
"electricity_meter_points": list(map(lambda mp: {
"mpan": mp["meterPoint"]["mpan"],
"meters": list(map(lambda m: {
"serial_number": m["serialNumber"],
"is_export": m["smartExportElectricityMeter"] != None,
"is_smart_meter": m["smartImportElectricityMeter"] != None or m["smartExportElectricityMeter"] != None,
"device_id": m["smartImportElectricityMeter"]["deviceId"] if m["smartImportElectricityMeter"] != None else None
}, mp["meterPoint"]["meters"])),
"agreements": list(map(lambda a: {
"valid_from": a["validFrom"],
"valid_to": a["validTo"],
"tariff_code": a["tariff"]["tariffCode"] if "tariff" in a and "tariffCode" in a["tariff"] else None,
"product_code": a["tariff"]["productCode"] if "tariff" in a and "productCode" in a["tariff"] else None,
}, mp["meterPoint"]["agreements"]))
"serial_number": m["serialNumber"],
"is_export": m["smartExportElectricityMeter"] != None,
"is_smart_meter": m["smartImportElectricityMeter"] != None or m["smartExportElectricityMeter"] != None,
"device_id": m["smartImportElectricityMeter"]["deviceId"] if m["smartImportElectricityMeter"] != None else None
},
mp["meterPoint"]["meters"]
if "meterPoint" in mp and "meters" in mp["meterPoint"] and mp["meterPoint"]["meters"] is not None
else []
)),
"agreements": list(map(lambda a: {
"valid_from": a["validFrom"],
"valid_to": a["validTo"],
"tariff_code": a["tariff"]["tariffCode"] if "tariff" in a and "tariffCode" in a["tariff"] else None,
"product_code": a["tariff"]["productCode"] if "tariff" in a and "productCode" in a["tariff"] else None,
},
mp["meterPoint"]["agreements"]
if "meterPoint" in mp and "agreements" in mp["meterPoint"] and mp["meterPoint"]["agreements"] is not None
else []
))
},
account_response_body["data"]["account"]["electricityAgreements"]
if "electricityAgreements" in account_response_body["data"]["account"] and account_response_body["data"]["account"]["electricityAgreements"] is not None
Expand All @@ -195,16 +203,24 @@ async def async_get_account(self, account_id):
"gas_meter_points": list(map(lambda mp: {
"mprn": mp["meterPoint"]["mprn"],
"meters": list(map(lambda m: {
"serial_number": m["serialNumber"],
"consumption_units": m["consumptionUnits"],
"device_id": m["smartGasMeter"]["deviceId"] if m["smartGasMeter"] != None else None
}, mp["meterPoint"]["meters"])),
"serial_number": m["serialNumber"],
"consumption_units": m["consumptionUnits"],
"device_id": m["smartGasMeter"]["deviceId"] if m["smartGasMeter"] != None else None
},
mp["meterPoint"]["meters"]
if "meterPoint" in mp and "meters" in mp["meterPoint"] and mp["meterPoint"]["meters"] is not None
else []
)),
"agreements": list(map(lambda a: {
"valid_from": a["validFrom"],
"valid_to": a["validTo"],
"tariff_code": a["tariff"]["tariffCode"] if "tariff" in a and "tariffCode" in a["tariff"] else None,
"product_code": a["tariff"]["productCode"] if "tariff" in a and "productCode" in a["tariff"] else None,
}, mp["meterPoint"]["agreements"]))
"valid_from": a["validFrom"],
"valid_to": a["validTo"],
"tariff_code": a["tariff"]["tariffCode"] if "tariff" in a and "tariffCode" in a["tariff"] else None,
"product_code": a["tariff"]["productCode"] if "tariff" in a and "productCode" in a["tariff"] else None,
},
mp["meterPoint"]["agreements"]
if "meterPoint" in mp and "agreements" in mp["meterPoint"] and mp["meterPoint"]["agreements"] is not None
else []
))
},
account_response_body["data"]["account"]["gasAgreements"]
if "gasAgreements" in account_response_body["data"]["account"] and account_response_body["data"]["account"]["gasAgreements"] is not None
Expand Down

0 comments on commit ee86fe0

Please sign in to comment.