Skip to content

Commit

Permalink
Update discovery.py
Browse files Browse the repository at this point in the history
  • Loading branch information
DigiH committed Jan 8, 2024
1 parent b648670 commit dc1521d
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions TheengsGateway/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,8 @@ def __init__(self, configuration: dict) -> None:
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(":", "")
pub_device_copy = pub_device.copy()

# Remove "track" if PUBLISH_ADVDATA is 0
if not self.configuration["publish_advdata"] and "track" in pub_device_copy:
pub_device_copy.pop("track", None)
pub_device_copy = self.copy_pub_device(pub_device)

device_data = json.dumps(pub_device_copy)
if (
Expand Down Expand Up @@ -257,3 +254,11 @@ def publish_device_tracker(
tracker["device"] = hadevice # type: ignore[assignment]

self.publish(json.dumps(tracker), config_topic, retain=True)

def copy_pub_device(self, device: dict) -> dict:
"""Copy pub_device and remove "track" if publish_advdata is false."""
# Remove "track" if PUBLISH_ADVDATA is 0
if not self.configuration["publish_advdata"] and "track" in device:
device.pop("track", None)

return device

0 comments on commit dc1521d

Please sign in to comment.