Skip to content

Commit 05c0113

Browse files
📝 Add docstrings to fix/ws_open_chck
Docstrings generation was requested by @JarbasAl. * #83 (comment) The following files were modified: * `hivemind_bus_client/client.py`
1 parent e3ed907 commit 05c0113

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

hivemind_bus_client/client.py

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,12 @@ def on_close(self, *args):
234234
super().on_close(*args)
235235

236236
def wait_for_handshake(self, timeout=5):
237+
"""
238+
Waits for the HiveMind handshake to complete; if the handshake is not set and the websocket connection is open, starts the handshake, otherwise waits for the websocket to open and retries.
239+
240+
Parameters:
241+
timeout (float): Number of seconds to wait for each handshake or connection attempt before retrying.
242+
"""
237243
self.handshake_event.wait(timeout=timeout)
238244
if not self.handshake_event.is_set():
239245
if self.connected_event.is_set():
@@ -340,19 +346,20 @@ def _handle_hive_protocol(self, message: HiveMessage):
340346
def emit(self, message: Union[MycroftMessage, HiveMessage],
341347
binary_type: HiveMindBinaryPayloadType = HiveMindBinaryPayloadType.UNDEFINED):
342348
"""
343-
Send a HiveMessage or MycroftMessage to the HiveMind network, injecting routing context for BUS messages and optionally sending binary payloads.
344-
345-
Parameters:
346-
message (MycroftMessage | HiveMessage): The message to send. If a MycroftMessage is provided it will be wrapped into a BUS HiveMessage.
347-
binary_type (HiveMindBinaryPayloadType): When sending binary payloads, indicates the binary payload subtype; defaults to UNDEFINED.
348-
349-
Notes:
350-
- For messages with msg_type == HiveMessageType.BUS, the function will ensure the payload.context contains routing fields (source, platform, destination, session) and will emit the payload to the client's internal bus before sending.
351-
- This method transmits the message over the client's WebSocket and may perform serialization, optional compression, and optional encryption depending on client configuration.
352-
353-
Raises:
354-
ValueError: If the client has not been started with run_forever() and the connection is not ready.
355-
"""
349+
Send a HiveMind message (or wrap and send a MycroftMessage) and optionally transmit it as a binary payload.
350+
351+
Parameters:
352+
message (MycroftMessage | HiveMessage): The outgoing message. A MycroftMessage will be wrapped into a BUS HiveMessage.
353+
binary_type (HiveMindBinaryPayloadType): Binary payload subtype to use when sending BINARY messages; defaults to UNDEFINED.
354+
355+
Behavior:
356+
- For BUS messages, ensures payload.context contains routing fields (source, platform, destination, session_id, site_id) and emits the payload to the client's internal bus before sending.
357+
- Chooses binary or text transport according to message type and client configuration; the payload may be compressed and/or encrypted based on client settings.
358+
359+
Raises:
360+
ValueError: If the client has not been started (run_forever() not executed) and therefore cannot send messages.
361+
RuntimeError: If the client was started but the websocket connection did not open within the wait period, preventing the message from being sent.
362+
"""
356363
if isinstance(message, MycroftMessage):
357364
message = HiveMessage(msg_type=HiveMessageType.BUS,
358365
payload=message)
@@ -537,4 +544,4 @@ def emit_intercom(self, message: Union[MycroftMessage, HiveMessage],
537544
signature = sign_RSA(private_key, encrypted_message)
538545

539546
self.emit(HiveMessage(HiveMessageType.INTERCOM, payload={"ciphertext": pybase64.b64encode(encrypted_message),
540-
"signature": pybase64.b64encode(signature)}))
547+
"signature": pybase64.b64encode(signature)}))

0 commit comments

Comments
 (0)