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

Fix setting MQTT socket buffer size with WebsocketWrapper #117672

Merged
merged 6 commits into from
May 20, 2024
Merged
Changes from 1 commit
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
7 changes: 6 additions & 1 deletion homeassistant/components/mqtt/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
TIMEOUT_ACK = 10
RECONNECT_INTERVAL_SECONDS = 10

type SocketType = socket.socket | ssl.SSLSocket | Any
type SocketType = socket.socket | ssl.SSLSocket | Any | "mqtt.WebsocketWrapper"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you don't need the quotes anymore, and may need an different rc/patch version of this PR as well as a dev version

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the cleanest is to take out the typing change for the patch and add it in a future PR so we can do a cherry pick.

I will write tests once I have stable power


type SubscribePayloadType = str | bytes # Only bytes if encoding is None

Expand Down Expand Up @@ -540,6 +540,11 @@

def _increase_socket_buffer_size(self, sock: SocketType) -> None:
"""Increase the socket buffer size."""
if not hasattr(sock, "setsockopt") and hasattr(sock, "_socket"):
# The WebsocketWrapper does not wrap setsockopt
# so we need to get the underlying socket
sock = sock._socket # noqa: SLF001

Check warning on line 546 in homeassistant/components/mqtt/client.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/mqtt/client.py#L546

Added line #L546 was not covered by tests

new_buffer_size = PREFERRED_BUFFER_SIZE
while True:
try:
Expand Down