Skip to content

Commit

Permalink
add factory reset dev path input
Browse files Browse the repository at this point in the history
  • Loading branch information
DamKast committed Oct 19, 2023
1 parent a4f2acb commit bae82da
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
9 changes: 6 additions & 3 deletions zigpy_zboss/tools/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ def get_serial_by_id_path():
return None


def get_config():
def get_config(argv=None):
"""Return the config used to connect to NCP."""
if path := get_serial_by_id_path():
CONFIG['device']['path'] = path
if argv:
CONFIG['device']['path'] = argv[0]
else:
if path := get_serial_by_id_path():
CONFIG['device']['path'] = path
print(f"Path used to connect to NCP: {CONFIG['device']['path']}\n")
return CONFIG
13 changes: 10 additions & 3 deletions zigpy_zboss/tools/factory_reset_ncp.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Script to factory reset the coordinator."""
import sys
import serial
import asyncio

Expand All @@ -15,10 +16,12 @@ async def factory_reset_ncp(config):
await nrf.reset(option=t.ResetOptions(2))


if __name__ == "__main__":
config = get_config()
async def main(argv):
"""Get config and factory reset NCP."""
config = get_config(argv)

try:
asyncio.run(factory_reset_ncp(config))
await factory_reset_ncp(config)
print("Coordinator successfully factory reset!")
except serial.serialutil.SerialException as exc:
print(f"Failed to factory reset coordinator! {exc}")
Expand All @@ -27,3 +30,7 @@ async def factory_reset_ncp(config):
f"Failed to factory reset coordinator! {exc2}\n"
"Power cycle the module and try again."
)


if __name__ == "__main__":
asyncio.run(main(sys.argv[1:]))

0 comments on commit bae82da

Please sign in to comment.