|
60 | 60 | have_powermon = False |
61 | 61 | powermon_exception = e |
62 | 62 | meter = None |
63 | | -from meshtastic.protobuf import channel_pb2, config_pb2, portnums_pb2 |
| 63 | +from meshtastic.protobuf import channel_pb2, config_pb2, portnums_pb2, mesh_pb2 |
64 | 64 | from meshtastic.version import get_active_version |
65 | 65 |
|
66 | 66 | logger = logging.getLogger(__name__) |
@@ -346,51 +346,56 @@ def onConnected(interface): |
346 | 346 | closeNow = True |
347 | 347 | waitForAckNak = True |
348 | 348 |
|
349 | | - # Validate owner names before connecting to device |
350 | | - if args.set_owner is not None: |
351 | | - stripped_long_name = args.set_owner.strip() |
352 | | - if not stripped_long_name: |
353 | | - meshtastic.util.our_exit("ERROR: Long Name cannot be empty or contain only whitespace characters") |
354 | | - |
355 | | - if hasattr(args, 'set_owner_short') and args.set_owner_short is not None: |
356 | | - stripped_short_name = args.set_owner_short.strip() |
357 | | - if not stripped_short_name: |
358 | | - meshtastic.util.our_exit("ERROR: Short Name cannot be empty or contain only whitespace characters") |
359 | | - |
360 | | - if args.set_owner and args.set_owner_short: |
361 | | - print(f"Setting device owner to {args.set_owner} and short name to {args.set_owner_short}") |
362 | | - elif args.set_owner: |
363 | | - print(f"Setting device owner to {args.set_owner}") |
364 | | - elif args.set_owner_short and not args.set_owner: |
365 | | - print(f"Setting device owner short to {args.set_owner_short}") |
366 | | - |
367 | | - if args.set_is_unmessageable: |
| 349 | + long_name = args.set_owner.strip() if args.set_owner else None |
| 350 | + short_name = args.set_owner_short.strip() if args.set_owner_short else None |
| 351 | + |
| 352 | + if long_name is not None and not long_name: |
| 353 | + meshtastic.util.our_exit("ERROR: Long Name cannot be empty or contain only whitespace characters") |
| 354 | + |
| 355 | + if short_name is not None and not short_name: |
| 356 | + meshtastic.util.our_exit("ERROR: Short Name cannot be empty or contain only whitespace characters") |
| 357 | + |
| 358 | + if long_name and short_name: |
| 359 | + print(f"Setting device owner to {long_name} and short name to {short_name}") |
| 360 | + elif long_name: |
| 361 | + print(f"Setting device owner to {long_name}") |
| 362 | + elif short_name: |
| 363 | + print(f"Setting device owner short to {short_name}") |
| 364 | + |
| 365 | + unmessagable = None |
| 366 | + if args.set_is_unmessageable is not None: |
368 | 367 | unmessagable = ( |
369 | 368 | meshtastic.util.fromStr(args.set_is_unmessageable) |
370 | 369 | if isinstance(args.set_is_unmessageable, str) |
371 | 370 | else args.set_is_unmessageable |
372 | 371 | ) |
| 372 | + print(f"Setting device owner is_unmessageable to {unmessagable}") |
373 | 373 |
|
374 | | - if unmessagable is not None: |
375 | | - print(f"Setting device owner is_unmessageable to {unmessagable}") |
376 | | - interface.getNode( |
377 | | - args.dest, False, **getNode_kwargs).setOwner(long_name=args.set_owner, |
378 | | - short_name=args.set_owner_short, is_unmessagable=unmessagable |
379 | | - ) |
| 374 | + interface.getNode(args.dest, False, **getNode_kwargs).setOwner( |
| 375 | + long_name=long_name, |
| 376 | + short_name=short_name, |
| 377 | + is_unmessagable=unmessagable |
| 378 | + ) |
380 | 379 |
|
381 | 380 | if args.set_canned_message: |
382 | 381 | closeNow = True |
383 | 382 | waitForAckNak = True |
384 | | - print(f"Setting canned plugin message to {args.set_canned_message}") |
385 | | - interface.getNode(args.dest, False, **getNode_kwargs).set_canned_message( |
386 | | - args.set_canned_message |
387 | | - ) |
| 383 | + node = interface.getNode(args.dest, False, **getNode_kwargs) |
| 384 | + if node.module_available(mesh_pb2.CANNEDMSG_CONFIG): |
| 385 | + print(f"Setting canned plugin message to {args.set_canned_message}") |
| 386 | + node.set_canned_message(args.set_canned_message) |
| 387 | + else: |
| 388 | + print("Canned Message module is excluded by firmware; skipping set.") |
388 | 389 |
|
389 | 390 | if args.set_ringtone: |
390 | 391 | closeNow = True |
391 | 392 | waitForAckNak = True |
392 | | - print(f"Setting ringtone to {args.set_ringtone}") |
393 | | - interface.getNode(args.dest, False, **getNode_kwargs).set_ringtone(args.set_ringtone) |
| 393 | + node = interface.getNode(args.dest, False, **getNode_kwargs) |
| 394 | + if node.module_available(mesh_pb2.EXTNOTIF_CONFIG): |
| 395 | + print(f"Setting ringtone to {args.set_ringtone}") |
| 396 | + node.set_ringtone(args.set_ringtone) |
| 397 | + else: |
| 398 | + print("External Notification is excluded by firmware; skipping ringtone set.") |
394 | 399 |
|
395 | 400 | if args.pos_fields: |
396 | 401 | # If --pos-fields invoked with args, set position fields |
|
0 commit comments