You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+91-12Lines changed: 91 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -637,35 +637,114 @@ with mistapi.websockets.sites.DeviceStatsEvents(apisession, site_ids=["<site_id>
637
637
638
638
### Device Utilities Usage
639
639
640
-
```python
641
-
from mistapi.device_utils import ap, ex
640
+
All device utility functions are **non-blocking**: they trigger the REST API call, start a WebSocket stream in the background, and return a `UtilResponse` immediately. Your script can continue processing while data streams in.
641
+
642
+
#### Callback style
642
643
643
-
# Ping from an AP
644
-
result = ap.ping(apisession, site_id, device_id, host="8.8.8.8")
645
-
print(result.ws_data)
644
+
Pass an `on_message` callback to process each result as it arrives:
646
645
647
-
# Retrieve ARP table from a switch
648
-
result = ex.retrieveArpTable(apisession, site_id, device_id)
All device utility functions return a `UtilResponse` object:
661
726
727
+
#### Attributes
728
+
662
729
| Attribute | Type | Description |
663
730
|-----------|------|-------------|
664
731
|`trigger_api_response`|`APIResponse`| The initial REST API response that triggered the device command. Contains `status_code`, `data`, and `headers` from the trigger request. |
665
732
|`ws_required`|`bool`|`True` if the command required a WebSocket connection to stream results (most diagnostic commands do). `False` if the REST response alone was sufficient. |
666
-
|`ws_data`|`list[str]`| Parsed result data extracted from the WebSocket stream. Each entry is a processed output line from the device (e.g., a line of ping output or an ARP table row). |
733
+
|`ws_data`|`list[str]`| Parsed result data extracted from the WebSocket stream. This list is **live** — it grows as messages arrive in the background, even before `wait()` is called. |
667
734
|`ws_raw_events`|`list[str]`| Raw, unprocessed WebSocket event payloads as received from the Mist API. Useful for debugging or custom parsing. |
668
735
736
+
#### Properties and Methods
737
+
738
+
| Method / Property | Returns | Description |
739
+
|-------------------|---------|-------------|
740
+
|`done`|`bool`|`True` if data collection is complete (or no WS was needed). |
741
+
|`wait(timeout=None)`|`UtilResponse`| Block until data collection is complete. Returns `self`. |
742
+
|`receive()`|`Generator`| Blocking generator that yields each processed message as it arrives. Exits when the WebSocket closes. |
743
+
|`disconnect()`|`None`| Stop the WebSocket connection early. |
744
+
|`await response`|`UtilResponse`| Non-blocking await for `asyncio` contexts. |
745
+
746
+
`UtilResponse` also supports the context manager protocol (`with` statement).
0 commit comments