Skip to content

Commit f986983

Browse files
authored
Merge pull request #126 from fbjerggaard/fix-125
Handle API errors gracefully
2 parents 5a0921d + ae63998 commit f986983

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

custom_components/monta/api.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,13 @@ async def async_get_charges(self, charge_point_id: int) -> any:
131131
headers={"authorization": f"Bearer {access_token}"},
132132
)
133133

134-
return sorted(response["data"], key=lambda charge: -charge["id"])
134+
charges = response.get("data")
135+
136+
if charges is None:
137+
_LOGGER.warning("No charges found in response!")
138+
charges = []
139+
140+
return sorted(charges, key=lambda charge: -charge["id"])
135141

136142
async def async_start_charge(self, charge_point_id: int) -> any:
137143
"""Start a charge."""
@@ -177,7 +183,13 @@ async def async_get_wallet_transactions(self) -> any:
177183
headers={"authorization": f"Bearer {access_token}"},
178184
)
179185

180-
return sorted(response["data"], key=lambda transaction: -transaction["id"])
186+
transactions = response.get("data")
187+
188+
if transactions is None:
189+
_LOGGER.warning("No transactions found in response!")
190+
transactions = []
191+
192+
return sorted(transactions, key=lambda transaction: -transaction["id"])
181193

182194
async def async_get_access_token(self) -> str:
183195
"""Get access token."""

0 commit comments

Comments
 (0)