remove last sync & fix wakeup time
This commit is contained in:
parent
c8b01106d8
commit
331a90ca32
23
main.py
23
main.py
@ -53,14 +53,6 @@ class GadgetbridgeMQTTPublisher:
|
||||
"state_class": "total",
|
||||
"query": self.query_monthly_steps,
|
||||
},
|
||||
{
|
||||
"name": "Last Sync",
|
||||
"unique_id": "last_sync",
|
||||
"state_topic": f"gadgetbridge/{self.device_name}/last_sync",
|
||||
"icon": "mdi:sync",
|
||||
"device_class": "timestamp",
|
||||
"query": self.query_last_sync,
|
||||
},
|
||||
{
|
||||
"name": "Battery Level",
|
||||
"unique_id": "battery_level",
|
||||
@ -244,13 +236,6 @@ class GadgetbridgeMQTTPublisher:
|
||||
)
|
||||
return cursor.fetchone()[0] or 0
|
||||
|
||||
def query_last_sync(self, cursor) -> Any:
|
||||
cursor.execute("SELECT MAX(TIMESTAMP) FROM HEART_PULSE_SAMPLE")
|
||||
last_sync_ts = cursor.fetchone()[0]
|
||||
return (
|
||||
datetime.fromtimestamp(last_sync_ts).isoformat() if last_sync_ts else None
|
||||
)
|
||||
|
||||
def query_battery_level(self, cursor) -> Any:
|
||||
cursor.execute(
|
||||
"SELECT LEVEL FROM BATTERY_LEVEL ORDER BY TIMESTAMP DESC LIMIT 1"
|
||||
@ -305,7 +290,13 @@ class GadgetbridgeMQTTPublisher:
|
||||
"SELECT WAKEUP_TIME FROM XIAOMI_SLEEP_TIME_SAMPLE ORDER BY TIMESTAMP DESC LIMIT 1"
|
||||
)
|
||||
row = cursor.fetchone()
|
||||
return datetime.fromtimestamp(row[0]).isoformat() if row and row[0] else None
|
||||
if row and row[0]:
|
||||
ts = row[0]
|
||||
# If timestamp is in milliseconds, convert to seconds
|
||||
if ts > 1e12:
|
||||
ts = ts // 1000
|
||||
return datetime.fromtimestamp(ts).isoformat()
|
||||
return None
|
||||
|
||||
def query_is_awake(self, cursor) -> Any:
|
||||
cursor.execute(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user