Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wsapp as member function to have ability to stop it #65

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/dirigera/hub/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def __init__(
self.api_base_url = f"https://{ip_address}:{port}/{api_version}"
self.websocket_base_url = f"wss://{ip_address}:{port}/{api_version}"
self.token = token
self.wsapp = None

def headers(self) -> Dict[str, Any]:
return {"Authorization": f"Bearer {self.token}"}
Expand Down Expand Up @@ -73,7 +74,7 @@ def create_event_listener(
on_cont_message (Any, optional)
ping_intervall (int, optional): Ping interval in Seconds. Defaults to 60.
"""
wsapp = websocket.WebSocketApp(
self.wsapp = websocket.WebSocketApp(
self.websocket_base_url,
header={"Authorization": f"Bearer {self.token}"},
on_open=on_open,
Expand All @@ -86,10 +87,14 @@ def create_event_listener(
on_cont_message=on_cont_message,
)

wsapp.run_forever(
self.wsapp.run_forever(
sslopt={"cert_reqs": ssl.CERT_NONE}, ping_interval=ping_intervall
)

def stop_event_listener(self):
if self.wsapp is not None:
self.wsapp.close()

def patch(self, route: str, data: List[Dict[str, Any]]) -> Any:
response = requests.patch(
f"{self.api_base_url}{route}",
Expand Down
Loading