diff --git a/modules/message_handler.py b/modules/message_handler.py index 0774bd9..6980619 100644 --- a/modules/message_handler.py +++ b/modules/message_handler.py @@ -2943,12 +2943,20 @@ class MessageHandler: # Add companion to device contact list try: - # Only pass the fields required by `add_contact` (name + optional public_key). - # `contact_data` may include RSSI/SNR values (often negative in dBm) which some - # device APIs treat as unsigned integers. - if public_key: - result = await self.bot.meshcore.commands.add_contact(contact_name, public_key) - else: + # Avoid passing `contact_data` wholesale: it can include RSSI/SNR values + # (often negative in dBm). Some device bindings cast those to unsigned + # ints and fail. + # + # The meshcore binding for `add_contact` is not consistent across versions, + # so we try (name, public_key) first, but fall back to (name) on + # signature mismatches. + try: + if public_key: + result = await self.bot.meshcore.commands.add_contact(contact_name, public_key) + else: + result = await self.bot.meshcore.commands.add_contact(contact_name) + except TypeError: + # Binding expects a single positional arg: `add_contact(name)` result = await self.bot.meshcore.commands.add_contact(contact_name) if hasattr(result, 'type') and result.type.name == 'OK': self.logger.info(f"✅ Companion {contact_name} added to device contacts")