Skip to content

Commit

Permalink
command_endpoints: sanitize result
Browse files Browse the repository at this point in the history
A command endpoint that inserts newlines in the speech result causes the
result to be printed outside of the display. We do not want to deal with
this in the Willow C code, and as we will eventually make WAS command
mode the default and rip out endpoint support from Willow, we can simply
do this in WAS.

As we're using a pydantic model for the command endpoint result, we can
easily do this with a sanitize function in the CommandEndpointResult
model, and call this when we initialize the CommandEndpointResponse.
We can't do it when we initialize the CommandEndpointResult, as we
sometimes change the speech attribute after init.
  • Loading branch information
stintel committed Dec 12, 2023
1 parent 19e4066 commit c0d5e73
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/internal/command_endpoints/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,17 @@ class CommandEndpointResult(BaseModel):
ok: bool = False
speech: str = "Error!"

def sanitize(self):
self.speech = self.speech.replace("\n", " ").replace("\r", " ").lstrip()


class CommandEndpointResponse(BaseModel):
result: CommandEndpointResult = None

def __init__(self, **kwargs):
super().__init__(**kwargs)
self.result.sanitize()


class CommandEndpoint():
name = "WAS CommandEndpoint"
Expand Down

0 comments on commit c0d5e73

Please sign in to comment.