Skip to content

Commit

Permalink
Fix accounts without bills
Browse files Browse the repository at this point in the history
  • Loading branch information
MiguelAngelLV committed May 23, 2023
1 parent d4d30c8 commit 79254f2
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions custom_components/octopus_spain/lib/octopus_spain.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,23 @@ async def account(self, account: str):
if not electricity:
raise Exception("Electricity ledger not found")

invoice = electricity["statementsWithDetails"]["edges"][0]["node"]
invoices = electricity["statementsWithDetails"]["edges"]

if len(invoices) == 0:
return {
'solar_wallet': None,
'last_invoice': {
'amount': None,
'issued': None,
'start': None,
'end': None
}
}

invoice = invoices[0]["node"]

# Los timedelta son bastante chapuzas, habrá que arreglarlo
data = {
return {
"solar_wallet": (float(solar_wallet["balance"]) / 100) if solar_wallet else 0,
"last_invoice": {
"amount": invoice["amount"] if invoice["amount"] else 0,
Expand All @@ -94,5 +107,3 @@ async def account(self, account: str):
"end": (datetime.fromisoformat(invoice["consumptionEndDate"]) - timedelta(seconds=1)).date(),
},
}

return data

0 comments on commit 79254f2

Please sign in to comment.