Skip to content

Commit a00baa9

Browse files
committed
Try adding a 2nd optional response
1 parent 3975ef9 commit a00baa9

File tree

2 files changed

+28
-17
lines changed

2 files changed

+28
-17
lines changed

tests/stick_test_data.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -596,15 +596,26 @@
596596
b"000000C1", # Success ack
597597
b"003A" # msg_id
598598
+ b"0098765432101234" # mac
599-
# 2025-04-03 22:00:30
600-
+ bytes(("%%0%dd" % 2) % 30, pw_constants.UTF8) # noqa: UP031
601-
+ bytes(("%%0%dd" % 2) % 0, pw_constants.UTF8) # noqa: UP031
602-
+ bytes(("%%0%dd" % 2) % 22, pw_constants.UTF8) # noqa: UP031
603-
+ bytes(("%%0%dd" % 2) % 5, pw_constants.UTF8) # noqa: UP031
604-
+ bytes(("%%0%dd" % 2) % 3, pw_constants.UTF8) # noqa: UP031
605-
+ bytes(("%%0%dd" % 2) % 4, pw_constants.UTF8) # noqa: UP031
606-
+ bytes(("%%0%dd" % 2) % 25, pw_constants.UTF8), # noqa: UP031
607-
),
599+
# datetime.now()
600+
+ bytes(("%%0%dd" % 2) % utc_now.second, pw_constants.UTF8) # noqa: UP031
601+
+ bytes(("%%0%dd" % 2) % utc_now.minute, pw_constants.UTF8) # noqa: UP031
602+
+ bytes(("%%0%dd" % 2) % utc_now.hour, pw_constants.UTF8) # noqa: UP031
603+
+ bytes(("%%0%dd" % 2) % utc_now.weekday(), pw_constants.UTF8) # noqa: UP031
604+
+ bytes(("%%0%dd" % 2) % utc_now.day, pw_constants.UTF8) # noqa: UP031
605+
+ bytes(("%%0%dd" % 2) % utc_now.month, pw_constants.UTF8) # noqa: UP031
606+
+ bytes(("%%0%dd" % 2) % (utc_now.year - 2000), pw_constants.UTF8), # noqa: UP031
607+
),
608+
# b"003A" # msg_id
609+
# + b"0098765432101234" # mac
610+
# # 2025-04-03 22:00:30
611+
# + bytes(("%%0%dd" % 2) % 30, pw_constants.UTF8) # noqa: UP031
612+
# + bytes(("%%0%dd" % 2) % 0, pw_constants.UTF8) # noqa: UP031
613+
# + bytes(("%%0%dd" % 2) % 22, pw_constants.UTF8) # noqa: UP031
614+
# + bytes(("%%0%dd" % 2) % 5, pw_constants.UTF8) # noqa: UP031
615+
# + bytes(("%%0%dd" % 2) % 3, pw_constants.UTF8) # noqa: UP031
616+
# + bytes(("%%0%dd" % 2) % 4, pw_constants.UTF8) # noqa: UP031
617+
# + bytes(("%%0%dd" % 2) % 25, pw_constants.UTF8), # noqa: UP031
618+
#),
608619
b"\x05\x05\x03\x0300280098765432101234000022030304259DDF\r\n": (
609620
"Circle+ Realtime set clock for 0098765432101234",
610621
b"000000C1", # Success ack

tests/test_usb.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,33 +101,33 @@ def write(self, data: bytes) -> None:
101101
"""Write data back to system."""
102102
log = None
103103
ack = None
104-
response = None
104+
response_1 = None
105105
if data in self._processed and self._second_response is not None:
106-
log, ack, response = self._second_response.get(data, (None, None, None))
106+
log, ack, response_1 = self._second_response.get(data, (None, None, None))
107107
if log is None and self._first_response is not None:
108-
log, ack, response = self._first_response.get(data, (None, None, None))
108+
log, ack, response_1 = self._first_response.get(data, (None, None, None))
109109
if log is None:
110110
resp = pw_userdata.PARTLY_RESPONSE_MESSAGES.get(
111111
data[:24], (None, None, None)
112112
)
113113
if resp is None:
114114
_LOGGER.debug("No msg response for %s", str(data))
115115
return
116-
log, ack, response = resp
116+
log, ack, response_1 = resp
117117
if ack is None:
118118
_LOGGER.debug("No ack response for %s", str(data))
119119
return
120120

121121
self._seq_id = inc_seq_id(self._seq_id)
122-
if response and self._msg == 0:
123-
self.message_response_at_once(ack, response, self._seq_id)
122+
if response_1 and self._msg == 0:
123+
self.message_response_at_once(ack, response_1, self._seq_id)
124124
self._processed.append(data)
125125
else:
126126
self.message_response(ack, self._seq_id)
127127
self._processed.append(data)
128-
if response is None or self._closing:
128+
if response_1 is None or self._closing:
129129
return
130-
self._loop.create_task(self._delayed_response(response, self._seq_id))
130+
self._loop.create_task(self._delayed_response(response_1, self._seq_id))
131131
self._msg += 1
132132

133133
async def _delayed_response(self, data: bytes, seq_id: bytes) -> None:

0 commit comments

Comments
 (0)