Skip to content

Commit

Permalink
ha_ws: prevent endless loop with WAC enabled
Browse files Browse the repository at this point in the history
If a command learned by WAC is no longer supported by Home Assistant, we
end up in an endless loop. Prevent this by adding a "final" boolean to
the connmap.
  • Loading branch information
stintel committed Feb 26, 2024
1 parent 628521f commit 4b6e0db
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions app/internal/command_endpoints/ha_ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,14 @@ async def cb_msg(self, msg):
self.log.debug(self.connmap[id])

if self.app.wac_enabled:
if self.connmap[id]["final"]:
return
wac_success, wac_command = wac_search(command)

if wac_success:
jsondata = self.connmap[id]["jsondata"]
jsondata["text"] = wac_command
self.send(jsondata, ws)
self.send(jsondata, ws, True)
self.connmap.pop(id)
return
else:
Expand All @@ -130,11 +132,12 @@ async def cb_msg(self, msg):
def parse_response(self, response):
return None

def send(self, jsondata, ws):
def send(self, jsondata, ws, final=False):
id = int(time.time() * 1000)

if id not in self.connmap:
self.connmap[id] = {
'final': final,
'jsondata': copy(jsondata),
'ws': ws,
}
Expand Down

0 comments on commit 4b6e0db

Please sign in to comment.