Skip to content

Commit

Permalink
Add option to override WebSocket max message size, for large HA installs
Browse files Browse the repository at this point in the history
  • Loading branch information
cbpowell committed May 6, 2023
1 parent 5860e8a commit bcde5f1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
15 changes: 13 additions & 2 deletions senselink/homeassistant/ha_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ class HAController:
bulk_rq_id = 2
data_sources = []

def __init__(self, url, auth_token):
def __init__(self, url, auth_token, max_ws_message_size=None):
self.url = url
self.auth_token = auth_token
self.max_ws_message = max_ws_message_size

async def connect(self):
# Create task
Expand All @@ -22,7 +23,17 @@ async def connect(self):
async def client_handler(self):
logging.info(f"Starting websocket client to URL: {self.url}")
try:
async with websockets.connect(self.url) as websocket:
if self.max_ws_message is not None:
max_ws_param = int(self.max_ws_message)
if max_ws_param > 0:
ws_args = {"uri": self.url, "max_size": max_ws_param}
else:
# Interpret 0 as None/No limit
ws_args = ws_args = {"uri": self.url, "max_size": None}
else:
ws_args = {"uri": self.url}

async with websockets.connect(**ws_args) as websocket:
self.ws = websocket
# Wait for incoming message from server
while True:
Expand Down
3 changes: 2 additions & 1 deletion senselink/senselink.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ def create_instances(self):
logging.error(f"Configuration error for Source {source_id}")
url = hass['url']
auth_token = hass['auth_token']
hass_controller = HAController(url, auth_token)
max_message_size = hass.get('max_message_size') or None
hass_controller = HAController(url, auth_token, max_ws_message_size=max_message_size)

# Generate plug instances
plugs = hass[PLUGS_KEY]
Expand Down

0 comments on commit bcde5f1

Please sign in to comment.