diff --git a/meshtastic/__main__.py b/meshtastic/__main__.py index 168540025..5bb6a0e91 100644 --- a/meshtastic/__main__.py +++ b/meshtastic/__main__.py @@ -158,11 +158,11 @@ def _printSetting(config_type, uni_name, pref_value, repeated): config_values = getattr(config, config_type.name) if not wholeField: pref_value = getattr(config_values, pref.name) - repeated = pref.label == pref.LABEL_REPEATED + repeated = _is_repeated_field(pref) _printSetting(config_type, uni_name, pref_value, repeated) else: for field in config_values.ListFields(): - repeated = field[0].label == field[0].LABEL_REPEATED + repeated = _is_repeated_field(field[0]) _printSetting(config_type, field[0].name, field[1], repeated) else: # Always show whole field for remote node @@ -253,7 +253,7 @@ def setPref(config, comp_name, raw_val) -> bool: return False # repeating fields need to be handled with append, not setattr - if pref.label != pref.LABEL_REPEATED: + if not _is_repeated_field(pref): try: if config_type.message_type is not None: config_values = getattr(config_part, config_type.name) @@ -1131,6 +1131,12 @@ def subscribe() -> None: # pub.subscribe(onNode, "meshtastic.node") +def _is_repeated_field(field_desc) -> bool: + """Return True if the protobuf field is repeated. Protobuf 6:3.10 and later us an is_repeated property""" + if hasattr(field_desc, "is_repeated"): + return bool(field_desc.is_repeated) + return field_desc.label == field_desc.LABEL_REPEATED + def set_missing_flags_false(config_dict: dict, true_defaults: set[tuple[str, str]]) -> None: """Ensure that missing default=True keys are present in the config_dict and set to False.""" for path in true_defaults: