Skip to content

Commit b1178e5

Browse files
committed
Add last webhook details to diagnostics
This partially resolves #85.
1 parent 5dbf58d commit b1178e5

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

custom_components/smartcar/diagnostics.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ async def async_get_config_entry_diagnostics(
3636
entry: ConfigEntry,
3737
) -> dict[str, Any]:
3838
"""Return diagnostics for a config entry."""
39+
meta_coordinator = entry.runtime_data.meta_coordinator
3940
coordinators: dict[str, SmartcarVehicleCoordinator] = (
4041
entry.runtime_data.coordinators
4142
)
@@ -54,6 +55,7 @@ async def async_get_config_entry_diagnostics(
5455
coordinator_name: coordinator.data
5556
for coordinator_name, coordinator in coordinators.items()
5657
},
58+
"metadata": meta_coordinator.data,
5759
},
5860
TO_REDACT,
5961
),

custom_components/smartcar/webhooks.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def update_meta_coordinator_data[F: Callable[..., Any], ReturnT](fn: F) -> F:
4646
async def wrapper(*args, **kwargs) -> ReturnT: # noqa: ANN002, ANN003
4747
response = await fn(*args, **kwargs)
4848
config_entry = kwargs["config_entry"]
49+
request = args[2]
4950
status = response.status
5051
data = response.text or (response.body and response.body.decode("utf-8"))
5152
meta_coordinator = config_entry.runtime_data.meta_coordinator
@@ -57,6 +58,7 @@ async def wrapper(*args, **kwargs) -> ReturnT: # noqa: ANN002, ANN003
5758
"status": status,
5859
**({"data": data} if data else {}),
5960
},
61+
"last_webhook_request": await request.text(),
6062
}
6163
)
6264
return cast("ReturnT", response)

tests/snapshots/test_diagnostics.ambr

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@
119119
'unique_id': 'a1d50709-3502-4faa-ba43-a5c7565e6a09',
120120
'version': 2,
121121
}),
122+
'metadata': dict({
123+
}),
122124
'webhook_url': None,
123125
})
124126
# ---
@@ -261,6 +263,8 @@
261263
'unique_id': 'a1d50709-3502-4faa-ba43-a5c7565e6a09',
262264
'version': 2,
263265
}),
266+
'metadata': dict({
267+
}),
264268
'webhook_url': None,
265269
})
266270
# ---

0 commit comments

Comments
 (0)