Skip to content

homematicip.connection.websocket_handler

homematicip.connection.websocket_handler

WebsocketHandler

Manages a WebSocket connection to Homematic IP and provides methods for starting, stopping, and processing messages. Supports automatic reconnect, adding handlers, and status queries.

add_on_connected_handler

add_on_connected_handler

Adds a handler that is called when the connection is established.

add_on_disconnected_handler

add_on_disconnected_handler

Adds a handler that is called when the connection is closed.

add_on_message_handler

add_on_message_handler

Adds a handler for incoming messages.

add_on_reconnect_handler

add_on_reconnect_handler

Adds a handler that is called when the connection is re-established.

add_on_stale_handler

add_on_stale_handler

Adds a handler called when the websocket reports connected but has gone silent past the configured thresholds.

Handler signature: handler(severity: str, seconds_since: float) where severity is "warning" (>= STALE_WARNING_SECONDS) or "error" (>= STALE_ERROR_SECONDS). Each severity fires at most once per staleness episode and resets when a fresh message arrives.

is_connected

is_connected

Returns True if the WebSocket connection is active.

is_running

is_running

Returns True if the reconnect loop is currently running.

last_disconnect_reason

last_disconnect_reason

Returns the last recorded disconnect or reconnect reason.

last_message_time

last_message_time

Returns the loop timestamp of the last received WebSocket message.

message_count

message_count

Returns the number of WebSocket messages received in this session.

reconnect_attempt_count

reconnect_attempt_count

Returns the number of reconnect attempts in the current outage.

seconds_since_last_message

seconds_since_last_message

Returns the seconds since the last WebSocket message was received.