File tree Expand file tree Collapse file tree 1 file changed +4
-3
lines changed Expand file tree Collapse file tree 1 file changed +4
-3
lines changed Original file line number Diff line number Diff line change @@ -43,6 +43,7 @@ def _parse_response(response: bytes) -> (int, str):
43
43
44
44
Returns:
45
45
(int, str): The board number and the value of the response.
46
+ If the response does not include a board number, we implicitly assume that it's the only board and always return board number = 0
46
47
47
48
Raises:
48
49
ValueError: If the response is invalid, cannot be decoded, or does not match the expected pattern.
@@ -59,11 +60,11 @@ def _parse_response(response: bytes) -> (int, str):
59
60
except UnicodeDecodeError :
60
61
raise ValueError (f"Invalid response: { response } " )
61
62
62
- regex = re .compile (r"^#BD:(\d{2}),CMD:OK(?:,VAL:(.+))?$" )
63
+ regex = re .compile (r"^#(?: BD:(?P<bd> \d{2}),)? CMD:OK(?:,VAL:(?P<val> .+))?$" )
63
64
match = regex .match (response )
64
65
if match is None :
65
66
raise ValueError (f"Invalid response: '{ response } '. Could not match regex" )
66
- bd = int (match .group (1 ))
67
- value : str | None = match .group (2 ) if match .group (2 ) else None
67
+ bd = int (match .group ("bd" )) if match . group ( "bd" ) else 0
68
+ value : str | None = match .group ("val" ) if match .group ("val" ) else None
68
69
69
70
return bd , value
You can’t perform that action at this time.
0 commit comments