fix FitnessTracker Name

This commit is contained in:
Oliver 2025-07-17 17:06:12 +00:00
parent 3228f76200
commit ab1589480a

10
main.py
View File

@ -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]: