diff --git a/main.py b/main.py index 03dd06d..73bd38a 100644 --- a/main.py +++ b/main.py @@ -115,14 +115,6 @@ class GadgetbridgeMQTTPublisher: "state_class": "total_increasing", "query": self.query_calories, }, - { - "name": "Wakeup Time", - "unique_id": "wakeup_time", - "state_topic": f"gadgetbridge/{self.device_name}/wakeup_time", - "icon": "mdi:weather-sunset-up", - "device_class": "timestamp", - "query": self.query_wakeup_time, - }, { "name": "Is Awake", "unique_id": "is_awake", @@ -284,32 +276,13 @@ class GadgetbridgeMQTTPublisher: row = cursor.fetchone() return row[0] if row else None - def query_wakeup_time(self, cursor) -> Any: - cursor.execute( - "SELECT WAKEUP_TIME FROM XIAOMI_SLEEP_TIME_SAMPLE ORDER BY TIMESTAMP DESC LIMIT 1" - ) - row = cursor.fetchone() - if row and row[0]: - ts = row[0] - try: - # Convert to int if needed - ts = int(float(ts)) - # If timestamp is in milliseconds, convert to seconds - if ts > 1e12: - ts = ts // 1000 - return datetime.fromtimestamp(ts).isoformat() - except Exception as e: - self.logger.error(f"Invalid WAKEUP_TIME timestamp: {ts} ({e})") - return None - return None - def query_is_awake(self, cursor) -> Any: cursor.execute( "SELECT IS_AWAKE FROM XIAOMI_SLEEP_TIME_SAMPLE ORDER BY TIMESTAMP DESC LIMIT 1" ) row = cursor.fetchone() # Return as boolean or string for Home Assistant - return bool(row[0]) if row else None + return not bool(row[0]) if row else None # inverted def query_total_sleep_duration(self, cursor) -> Any: cursor.execute(