Skip to content

Commit 4351159

Browse files
committed
reorganize websocket files
1 parent 1d01bc2 commit 4351159

21 files changed

Lines changed: 660 additions & 867 deletions

CLAUDE.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
This is the repo for my Mist API Python client, which is a wrapper around the Mist API. It allows you to easily interact with the Mist API and perform various actions such as creating and managing devices, sites, and more.
2+
3+
The code in src/mistapi/api is automatically generated from the OpenAPI specification provided by Mist. This means that the code is always up to date with the latest version of the API, and you can be confident that it will work correctly with the Mist API.
4+
The code in src/mistapi/api is organized into different modules, each corresponding to a different aspect of the Mist API. For example, there are modules for managing devices, sites, and more. Each module contains functions that correspond to the various endpoints of the Mist API, allowing you to easily perform actions such as creating a new device, retrieving information about a site, and more.
5+
6+
7+
The code in src/mistapi/websocket is here to provide a WebSocket client for the Mist API. This allows you to receive real-time updates from the Mist API, such as when a new device is added or when a site is updated. The WebSocket client is built using the popular websocket-client library, and it provides an easy-to-use interface for connecting to the Mist API and receiving updates.

src/mistapi/websockets/location.py

Lines changed: 244 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,244 @@
1+
"""
2+
--------------------------------------------------------------------------------
3+
------------------------- Mist API Python CLI Session --------------------------
4+
5+
Written by: Thomas Munzer (tmunzer@juniper.net)
6+
Github : https://github.com/tmunzer/mistapi_python
7+
8+
This package is licensed under the MIT License.
9+
10+
--------------------------------------------------------------------------------
11+
WebSocket channel for Location events.
12+
"""
13+
14+
from mistapi import APISession
15+
from mistapi.websockets.__ws_client import _MistWebsocket
16+
17+
18+
class LocationBleAssetsEvents(_MistWebsocket):
19+
"""WebSocket stream for location BLE assets events.
20+
21+
Subscribes to the ``/sites/{site_id}/stats/maps/{map_id}/assets`` channel and delivers
22+
real-time BLE assets events for the given location.
23+
24+
PARAMS
25+
-----------
26+
mist_session : mistapi.APISession
27+
Authenticated API session.
28+
site_id : str
29+
UUID of the site to stream events from.
30+
map_id : str
31+
UUID of the map to stream events from.
32+
33+
EXAMPLE
34+
-----------
35+
Callback style (background thread)::
36+
37+
ws = LocationBleAssetsEvents(session, site_id="abc123", map_id="def456")
38+
ws.on_message(lambda data: print(data))
39+
ws.connect()
40+
input("Press Enter to stop")
41+
ws.disconnect()
42+
43+
Generator style (background thread)::
44+
45+
ws = LocationBleAssetsEvents(session, site_id="abc123", map_id="def456")
46+
ws.connect(run_in_background=True)
47+
for msg in ws.receive():
48+
process(msg)
49+
50+
Context manager::
51+
52+
with LocationBleAssetsEvents(session, site_id="abc123", map_id="def456") as ws:
53+
ws.on_message(my_handler)
54+
time.sleep(60)
55+
"""
56+
57+
def __init__(self, mist_session: APISession, site_id: str, map_id: str) -> None:
58+
super().__init__(
59+
mist_session, channel=f"/sites/{site_id}/stats/maps/{map_id}/assets"
60+
)
61+
62+
63+
class LocationConnectedClientsEvents(_MistWebsocket):
64+
"""WebSocket stream for location connected clients events.
65+
66+
Subscribes to the ``/sites/{site_id}/stats/maps/{map_id}/clients`` channel and delivers
67+
real-time connected clients events for the given location.
68+
69+
PARAMS
70+
-----------
71+
mist_session : mistapi.APISession
72+
Authenticated API session.
73+
site_id : str
74+
UUID of the site to stream events from.
75+
map_id : str
76+
UUID of the map to stream events from.
77+
78+
EXAMPLE
79+
-----------
80+
Callback style (background thread)::
81+
82+
ws = LocationConnectedClientsEvents(session, site_id="abc123", map_id="def456")
83+
ws.on_message(lambda data: print(data))
84+
ws.connect()
85+
input("Press Enter to stop")
86+
ws.disconnect()
87+
88+
Generator style (background thread)::
89+
90+
ws = LocationConnectedClientsEvents(session, site_id="abc123", map_id="def456")
91+
ws.connect(run_in_background=True)
92+
for msg in ws.receive():
93+
process(msg)
94+
95+
Context manager::
96+
97+
with LocationConnectedClientsEvents(session, site_id="abc123", map_id="def456") as ws:
98+
ws.on_message(my_handler)
99+
time.sleep(60)
100+
"""
101+
102+
def __init__(self, mist_session: APISession, site_id: str, map_id: str) -> None:
103+
super().__init__(
104+
mist_session,
105+
channel=f"/sites/{site_id}/stats/maps/{map_id}/clients",
106+
)
107+
108+
109+
class LocationSdkClientsEvents(_MistWebsocket):
110+
"""WebSocket stream for location SDK clients events.
111+
112+
Subscribes to the ``/sites/{site_id}/stats/maps/{map_id}/sdkclients`` channel and delivers
113+
real-time SDK clients events for the given location.
114+
115+
PARAMS
116+
-----------
117+
mist_session : mistapi.APISession
118+
Authenticated API session.
119+
site_id : str
120+
UUID of the site to stream events from.
121+
map_id : str
122+
UUID of the map to stream events from.
123+
124+
EXAMPLE
125+
-----------
126+
Callback style (background thread)::
127+
128+
ws = LocationSdkClientsEvents(session, site_id="abc123", map_id="def456")
129+
ws.on_message(lambda data: print(data))
130+
ws.connect()
131+
input("Press Enter to stop")
132+
ws.disconnect()
133+
134+
Generator style (background thread)::
135+
136+
ws = LocationSdkClientsEvents(session, site_id="abc123", map_id="def456")
137+
ws.connect(run_in_background=True)
138+
for msg in ws.receive():
139+
process(msg)
140+
141+
Context manager::
142+
143+
with LocationSdkClientsEvents(session, site_id="abc123", map_id="def456") as ws:
144+
ws.on_message(my_handler)
145+
time.sleep(60)
146+
"""
147+
148+
def __init__(self, mist_session: APISession, site_id: str, map_id: str) -> None:
149+
super().__init__(
150+
mist_session,
151+
channel=f"/sites/{site_id}/stats/maps/{map_id}/sdkclients",
152+
)
153+
154+
155+
class LocationUnconnectedClientsEvents(_MistWebsocket):
156+
"""WebSocket stream for location unconnected clients events.
157+
158+
Subscribes to the ``/sites/{site_id}/stats/maps/{map_id}/unconnected_clients`` channel and delivers
159+
real-time unconnected clients events for the given location.
160+
161+
PARAMS
162+
-----------
163+
mist_session : mistapi.APISession
164+
Authenticated API session.
165+
site_id : str
166+
UUID of the site to stream events from.
167+
map_id : str
168+
UUID of the map to stream events from.
169+
170+
EXAMPLE
171+
-----------
172+
Callback style (background thread)::
173+
174+
ws = LocationUnconnectedClientsEvents(session, site_id="abc123", map_id="def456")
175+
ws.on_message(lambda data: print(data))
176+
ws.connect()
177+
input("Press Enter to stop")
178+
ws.disconnect()
179+
180+
Generator style (background thread)::
181+
182+
ws = LocationUnconnectedClientsEvents(session, site_id="abc123", map_id="def456")
183+
ws.connect(run_in_background=True)
184+
for msg in ws.receive():
185+
process(msg)
186+
187+
Context manager::
188+
189+
with LocationUnconnectedClientsEvents(session, site_id="abc123", map_id="def456") as ws:
190+
ws.on_message(my_handler)
191+
time.sleep(60)
192+
"""
193+
194+
def __init__(self, mist_session: APISession, site_id: str, map_id: str) -> None:
195+
super().__init__(
196+
mist_session,
197+
channel=f"/sites/{site_id}/stats/maps/{map_id}/unconnected_clients",
198+
)
199+
200+
201+
class LocationDiscoveredBleAssetsEvents(_MistWebsocket):
202+
"""WebSocket stream for location discovered BLE assets events.
203+
204+
Subscribes to the ``/sites/{site_id}/stats/maps/{map_id}/discovered_assets`` channel and delivers
205+
real-time discovered BLE assets events for the given location.
206+
207+
PARAMS
208+
-----------
209+
mist_session : mistapi.APISession
210+
Authenticated API session.
211+
site_id : str
212+
UUID of the site to stream events from.
213+
map_id : str
214+
UUID of the map to stream events from.
215+
216+
EXAMPLE
217+
-----------
218+
Callback style (background thread)::
219+
220+
ws = LocationDiscoveredBleAssetsEvents(session, site_id="abc123", map_id="def456")
221+
ws.on_message(lambda data: print(data))
222+
ws.connect()
223+
input("Press Enter to stop")
224+
ws.disconnect()
225+
226+
Generator style (background thread)::
227+
228+
ws = LocationDiscoveredBleAssetsEvents(session, site_id="abc123", map_id="def456")
229+
ws.connect(run_in_background=True)
230+
for msg in ws.receive():
231+
process(msg)
232+
233+
Context manager::
234+
235+
with LocationDiscoveredBleAssetsEvents(session, site_id="abc123", map_id="def456") as ws:
236+
ws.on_message(my_handler)
237+
time.sleep(60)
238+
"""
239+
240+
def __init__(self, mist_session: APISession, site_id: str, map_id: str) -> None:
241+
super().__init__(
242+
mist_session,
243+
channel=f"/sites/{site_id}/stats/maps/{map_id}/discovered_assets",
244+
)

src/mistapi/websockets/location/__init__.py

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/mistapi/websockets/location/ble_assets.py

Lines changed: 0 additions & 60 deletions
This file was deleted.

src/mistapi/websockets/location/clients_connected.py

Lines changed: 0 additions & 61 deletions
This file was deleted.

0 commit comments

Comments
 (0)