Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
DigiH committed Jan 13, 2024
1 parent 8de1b10 commit 0c9c810
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
11 changes: 8 additions & 3 deletions TheengsGateway/ble_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,12 +328,17 @@ async def update_clock_times(self) -> None:
)

def check_tracker_timeout(self) -> None:
"""Check if tracker timeout is over timeout limit. if not update the last received time."""
"""Check if tracker timeout is over timeout limit."""
for address, timestamp in self.discovered_trackers.copy().items():
if round(time()) - timestamp >= self.configuration["tracker_timeout"] and timestamp != 0:
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
message = json.dumps({'id': address, 'state': "offline", 'unlocked': False})
message = json.dumps(
+ {"id": address, "state": "offline", "unlocked": False}
+ )
self.publish(
message,
self.configuration["publish_topic"]
Expand Down
10 changes: 5 additions & 5 deletions TheengsGateway/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,6 @@ def publish_device_info(self, pub_device) -> None: # noqa: ANN001
"""Publish sensor directly to Home Assistant via MQTT discovery."""
pub_device_uuid = pub_device["id"].replace(":", "")

# Check if tracker is in the discovered_trackers dict and if any trackers are over the timeout limit
if "track" in pub_device:
self.discovered_trackers[pub_device["id"]] = round(time())
logger.debug("Discovered Trackers: %s", self.discovered_trackers)

pub_device_copy = self.copy_pub_device(pub_device)

device_data = json.dumps(pub_device_copy)
Expand Down Expand Up @@ -264,6 +259,11 @@ def publish_device_tracker(

def copy_pub_device(self, device: dict) -> dict:
"""Copy pub_device and remove "track" if publish_advdata is false."""
# Update tracker last received time
if "track" in device:
self.discovered_trackers[device["id"]] = round(time())
logger.debug("Discovered Trackers: %s", self.discovered_trackers)

pub_device_copy = device.copy()
# Remove "track" if PUBLISH_ADVDATA is 0
if not self.configuration["publish_advdata"] and "track" in pub_device_copy:
Expand Down

0 comments on commit 0c9c810

Please sign in to comment.