remove wakeuptime

This commit is contained in:
Oliver Großkloß 2025-07-17 13:35:09 +02:00
parent 7a208b8ceb
commit 5ebd34f8ef

29
main.py
View File

@ -115,14 +115,6 @@ class GadgetbridgeMQTTPublisher:
"state_class": "total_increasing", "state_class": "total_increasing",
"query": self.query_calories, "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", "name": "Is Awake",
"unique_id": "is_awake", "unique_id": "is_awake",
@ -284,32 +276,13 @@ class GadgetbridgeMQTTPublisher:
row = cursor.fetchone() row = cursor.fetchone()
return row[0] if row else None 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: def query_is_awake(self, cursor) -> Any:
cursor.execute( cursor.execute(
"SELECT IS_AWAKE FROM XIAOMI_SLEEP_TIME_SAMPLE ORDER BY TIMESTAMP DESC LIMIT 1" "SELECT IS_AWAKE FROM XIAOMI_SLEEP_TIME_SAMPLE ORDER BY TIMESTAMP DESC LIMIT 1"
) )
row = cursor.fetchone() row = cursor.fetchone()
# Return as boolean or string for Home Assistant # 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: def query_total_sleep_duration(self, cursor) -> Any:
cursor.execute( cursor.execute(