Skip to content

Commit

Permalink
Handle missing data (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
Danielhiversen authored Sep 11, 2023
1 parent 1ff42d1 commit 974ca0f
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions mill/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,12 +399,26 @@ def init_from_response(
device_stats: dict | None = None,
) -> MillDevice:
"""Class method."""
device_type = device_data.get("deviceType")
if device_type is None:
model = None
else:
child_type = device_type.get("childType")
if child_type is None:
model = None
else:
model = child_type.get("name")
last_metrics = device_data.get("lastMetrics")
if last_metrics is None:
report_time = None
else:
report_time = last_metrics.get("time")
return cls(
name=device_data.get("customName"),
device_id=device_data.get("deviceId"),
available=device_data.get("isConnected"),
model=device_data.get("deviceType", {}).get("childType", {}).get("name"),
report_time=device_data.get("lastMetrics", {}).get("time"),
model=model,
report_time=report_time,
data=device_data,
room_data=room_data,
stats=device_stats,
Expand Down

0 comments on commit 974ca0f

Please sign in to comment.