Skip to content

Commit fc07efe

Browse files
author
sidey79
committed
fix: correct command response pattern access in controller and add pattern for CG command
1 parent 1942951 commit fc07efe

2 files changed

Lines changed: 18 additions & 9 deletions

File tree

signalduino/commands.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,13 @@ async def ping(self, timeout: float = 2.0) -> str:
7575

7676
async def get_config(self, timeout: float = 2.0) -> Dict[str, int]:
7777
"""Decoder configuration (CG) - Returns parsed dictionary."""
78-
response = await self._send_command(command="CG", expect_response=True, timeout=timeout)
78+
config_pattern = re.compile(r'^MS=[01];MU=[01];MC=[01];Mred=[01](;M[A-Za-z0-9]+=[01])*$')
79+
response = await self._send_command(
80+
command="CG",
81+
expect_response=True,
82+
timeout=timeout,
83+
response_pattern=config_pattern
84+
)
7985
return self._parse_decoder_config(response)
8086

8187
async def get_ccconf(self, timeout: float = 2.0) -> Dict[str, str]:

signalduino/controller.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -360,17 +360,20 @@ async def _handle_as_command_response(self, line: str) -> None:
360360
self.logger.debug(f"Current pending responses: {len(self._pending_responses)}")
361361
for pending in self._pending_responses:
362362
try:
363-
self.logger.debug(f"Checking pending response: {pending.payload}")
364-
if pending.response_pattern:
365-
self.logger.debug(f"Testing pattern: {pending.response_pattern}")
366-
if pending.response_pattern.match(line):
367-
self.logger.debug(f"Matched response pattern for command: {pending.payload}")
363+
self.logger.debug(f"Checking pending response for command: {pending.command.payload}. Line: {line.strip()}")
364+
365+
pattern = pending.command.response_pattern
366+
if pattern:
367+
self.logger.debug(f"Testing pattern: {pattern.pattern}")
368+
if pattern.match(line):
369+
self.logger.debug(f"Matched response pattern for command: {pending.command.payload}")
368370
pending.future.set_result(line)
369371
self._pending_responses.remove(pending)
370372
return
371-
self.logger.debug(f"Testing direct match for: {pending.payload}")
372-
if line.startswith(pending.payload):
373-
self.logger.debug(f"Matched direct response for command: {pending.payload}")
373+
374+
self.logger.debug(f"Testing direct match for: {pending.command.payload}")
375+
if line.startswith(pending.command.payload):
376+
self.logger.debug(f"Matched direct response for command: {pending.command.payload}")
374377
pending.future.set_result(line)
375378
self._pending_responses.remove(pending)
376379
return

0 commit comments

Comments
 (0)