Skip to content

Commit 2132040

Browse files
James Boultonclaude
andcommitted
CLK: take the time from the last field, so the app's request ID works
The Dash app sends CLK <request ID> <epoch>. Only srv_clk was taken as a request ID, so the app's ID was read as the time, the clock wasn't set, and the app never got CLK back to close its Setting Time popup. As in zephyr-dashio, any request ID but srv_clk is the app's. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 48d1429 commit 2132040

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

‎dashio/device.py‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -382,13 +382,17 @@ def unset_saf_end_callback(self):
382382
self._saf_end_callback = None
383383

384384
def _clk_rx_event(self, msg) -> str:
385-
"""CLK with the time: from the Dash app, `\\t<id>\\tCLK\\t<epoch>`, or the Dash server's reply to
386-
request_clock(), `\\t<id>\\tCLK\\tsrv_clk\\t<epoch>`. The app is answered with a bare CLK when the
387-
clock is set. The server isn't: a CLK to the server asks it for the time again."""
388-
from_server = len(msg) > 2 and msg[2] == SERVER_CLOCK_ID
385+
"""CLK with the time, the last field: from the Dash app, `\\t<id>\\tCLK\\t<epoch>` or
386+
`\\t<id>\\tCLK\\t<request ID>\\t<epoch>`, or the Dash server's reply to request_clock(),
387+
`\\t<id>\\tCLK\\tsrv_clk\\t<epoch>`. The app is answered with a bare CLK when the clock is set.
388+
The server isn't: a CLK to the server asks it for the time again."""
389+
if len(msg) < 3:
390+
return ""
391+
from_server = len(msg) > 3 and msg[2] == SERVER_CLOCK_ID
389392
try:
390-
utc = int(float(msg[3] if from_server else msg[2]))
391-
except (IndexError, ValueError):
393+
utc = int(float(msg[-1]))
394+
except ValueError:
395+
logger.debug("CLK without a time: %s", msg)
392396
return ""
393397
if self._clk_rx_callback is not None and self._clk_rx_callback(utc) and not from_server:
394398
return self._device_id_str + "\tCLK\n"

‎tests/test_device_setup.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ def test_clock_from_app(self):
7878
self.assertEqual(self.command("\tDEVICEID\tCLK\t1762819200\n"), "\tDEVICEID\tCLK\n", "The app waits for a bare CLK back")
7979
self.assertEqual(times, [1762819200])
8080

81+
def test_clock_from_app_with_request_id(self):
82+
times = []
83+
self.device.set_clock_callback(lambda utc: times.append(utc) or True)
84+
self.assertEqual(self.command("\tDEVICEID\tCLK\tR2\t1762819200\n"), "\tDEVICEID\tCLK\n",
85+
"Any request ID but srv_clk is the app's, and the app waits for CLK back")
86+
self.assertEqual(times, [1762819200])
87+
8188
def test_clock_not_set(self):
8289
self.device.set_clock_callback(lambda utc: False)
8390
self.assertEqual(self.command("\tDEVICEID\tCLK\t1762819200\n"), "", "Only a clock that was set is confirmed")

0 commit comments

Comments
 (0)