Skip to content

Commit

Permalink
fixed a crash when a key in units response is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
Kleinrotti committed Dec 28, 2024
1 parent 0abffe0 commit 7eb5049
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/senertec/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,19 +383,19 @@ def getUnits(self) -> list[energyUnit]:
if response.status_code == 200:
values = json.loads(response.text)
units = []
for x in values["units"]:
for x in values.get("units", []):
unit = energyUnit()
unit.model = x["benennung"]
unit.serial = x["seriennummer"]
unit.connected = x["connected"]
unit.online = x["online"]
unit.itemNumber = x["artikelNummer"]
unit.contact = x["standortAnsprech"]
unit.city = x["standortOrt"]
unit.locationName = x["standortName"]
unit.postalCode = x["standortPlz"]
unit.street = x["standortAdresse"]
unit.productGroup = x["productGroup"]
unit.model = x.get("benennung", "")
unit.serial = x.get("seriennummer", "")
unit.connected = x.get("connected", "")
unit.online = x.get("online", "")
unit.itemNumber = x.get("artikelNummer", "")
unit.contact = x.get("standortAnsprech", "")
unit.city = x.get("standortOrt", "")
unit.locationName = x.get("standortName", "")
unit.postalCode = x.get("standortPlz", "")
unit.street = x.get("standortAdresse", "")
unit.productGroup = x.get("productGroup", "")
units.append(unit)
self.__logger__.debug(
f"Successful received a list of {len(units)} units.")
Expand Down

0 comments on commit 7eb5049

Please sign in to comment.