Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions bellows/cli/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,10 @@ async def setup(dev, baudrate, cbh=None, configure=True):
if cbh:
s.add_callback(cbh)
try:
await s.connect()
await s.init()
except Exception as e:
LOGGER.error(e)
raise click.Abort()
LOGGER.debug("Connected. Resetting.")
await s.reset()
await s.version()

async def cfg(config_id, value):
v = await s.setConfigurationValue(config_id, value)
Expand Down
38 changes: 24 additions & 14 deletions bellows/ezsp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,36 +80,46 @@ async def _probe(self) -> None:
async def initialize(cls, zigpy_config: Dict) -> "EZSP":
"""Return initialized EZSP instance."""
ezsp = cls(zigpy_config[CONF_DEVICE])
await ezsp.connect()

await ezsp.init()

try:
await ezsp._protocol.initialize(zigpy_config)

if zigpy_config[CONF_PARAM_SRC_RTG]:
await ezsp.set_source_routing()
except Exception:
ezsp.close()
raise

return ezsp

async def init(self) -> None:
await self.connect()

# `zigbeed` resets on startup
if zigpy_config[CONF_DEVICE][CONF_DEVICE_PATH].startswith("socket://"):
if self._config[CONF_DEVICE_PATH].startswith("socket://"):
try:
await asyncio.wait_for(
ezsp._gw.wait_for_startup_reset(),
self._gw.wait_for_startup_reset(),
NETWORK_COORDINATOR_STARTUP_RESET_WAIT,
)
except asyncio.TimeoutError:
pass
else:
LOGGER.debug("Received a reset on startup, not resetting again")
ezsp.start_ezsp()
self.start_ezsp()

try:
if not ezsp.is_ezsp_running:
await ezsp.reset()
if not self.is_ezsp_running:
LOGGER.debug("Connected. Resetting.")
await self.reset()

await ezsp.version()
await ezsp._protocol.initialize(zigpy_config)

if zigpy_config[CONF_PARAM_SRC_RTG]:
await ezsp.set_source_routing()
await self.version()
except Exception:
ezsp.close()
self.close()
raise

return ezsp

async def connect(self) -> None:
assert self._gw is None
self._gw = await bellows.uart.connect(self._config, self)
Expand Down