diff --git a/main.py b/main.py index dfa1370..5a8d5d6 100644 --- a/main.py +++ b/main.py @@ -354,14 +354,20 @@ class GadgetbridgeMQTTPublisher: self.logger.error(f"Failed to connect to MQTT broker: {e}") def get_device_alias(self) -> str: - """Fetch ALIAS from DEVICE table for device_name""" + """Fetch ALIAS from DEVICE table for device_name where NAME contains 'band' or 'watch' (case-insensitive)""" if not os.path.exists(self.db_path): self.logger.error(f"Database file not found: {self.db_path}") return "fitness_tracker" try: conn = sqlite3.connect(self.db_path) cursor = conn.cursor() - cursor.execute("SELECT ALIAS FROM DEVICE LIMIT 1") + cursor.execute( + """ + SELECT ALIAS FROM DEVICE + WHERE LOWER(NAME) LIKE '%band%' OR LOWER(NAME) LIKE '%watch%' + LIMIT 1 + """ + ) row = cursor.fetchone() conn.close() if row and row[0]: