Skip to content

Commit 890e559

Browse files
committed
Move retrying out of connect and into startup_reset
1 parent 02d7870 commit 890e559

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

bellows/ezsp/__init__.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def is_tcp_serial_port(self) -> bool:
109109
parsed_path = urllib.parse.urlparse(self._config[conf.CONF_DEVICE_PATH])
110110
return parsed_path.scheme == "socket"
111111

112-
async def startup_reset(self) -> None:
112+
async def _startup_reset(self) -> None:
113113
"""Start EZSP and reset the stack."""
114114
# `zigbeed` resets on startup
115115
if self.is_tcp_serial_port:
@@ -128,15 +128,12 @@ async def startup_reset(self) -> None:
128128
await self.version()
129129
await self.get_xncp_features()
130130

131-
async def connect(self, *, use_thread: bool = True) -> None:
132-
assert self._gw is None
133-
self._gw = await bellows.uart.connect(self._config, self, use_thread=use_thread)
134-
131+
async def startup_reset(self) -> None:
135132
for attempt in range(RESET_ATTEMPTS):
136133
self._protocol = v4.EZSPv4(self.handle_callback, self._gw)
137134

138135
try:
139-
await self.startup_reset()
136+
await self._startup_reset()
140137
break
141138
except Exception as exc:
142139
if attempt + 1 < RESET_ATTEMPTS:
@@ -151,6 +148,11 @@ async def connect(self, *, use_thread: bool = True) -> None:
151148
await self.disconnect()
152149
raise
153150

151+
async def connect(self, *, use_thread: bool = True) -> None:
152+
assert self._gw is None
153+
self._gw = await bellows.uart.connect(self._config, self, use_thread=use_thread)
154+
await self.startup_reset()
155+
154156
async def reset(self):
155157
LOGGER.debug("Resetting EZSP")
156158
self.stop_ezsp()

0 commit comments

Comments
 (0)