Skip to content

Commit

Permalink
"presence": "absent"
Browse files Browse the repository at this point in the history
  • Loading branch information
DigiH committed Feb 10, 2024
1 parent b4057f9 commit d9b385e
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions TheengsGateway/ble_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,29 +338,26 @@ async def update_clock_times(self) -> None:

def check_tracker_timeout(self) -> None:
"""Check if tracker timeout is over timeout limit."""
# If the timestamp is later than current time minus tracker_timeout
# Publish offline message
for address, timestamp in self.discovered_trackers.copy().items():
if (
round(time()) - timestamp >= self.configuration["tracker_timeout"]
and timestamp != 0
):
# If the timestamp is later than current time minus tracker_timeout
# Publish offline message
if self.configuration["discovery"]:
message = json.dumps({"id": address, "state": "offline"})
elif self.configuration["general_presence"]:
message = json.dumps({"id": address, "presence": "absent"})

if (
and (
self.configuration["discovery"]
or self.configuration["general_presence"]
):
self.publish(
message,
self.configuration["publish_topic"]
+ "/"
+ address.replace(":", ""),
)
self.discovered_trackers[address] = 0
)
):
message = json.dumps({"id": address, "presence": "absent"})

self.publish(
message,
self.configuration["publish_topic"]
+ "/"
+ address.replace(":", ""),
)
self.discovered_trackers[address] = 0

async def ble_scan_loop(self) -> None:
"""Scan for BLE devices."""
Expand Down

0 comments on commit d9b385e

Please sign in to comment.