Skip to content

Commit

Permalink
feat: add extra attributes to device_tracker (#371)
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasbrett authored Mar 10, 2024
1 parent 97a08d2 commit cac4af9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
15 changes: 15 additions & 0 deletions custom_components/weenect/device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,18 @@ def location_accuracy(self):
if self.id in self.coordinator.data:
if self.coordinator.data[self.id]["position"]:
return self.coordinator.data[self.id]["position"][0]["radius"]

@property
def extra_state_attributes(self):
"""Return device specific attributes."""
res = self._attr_extra_state_attributes

if self.id in self.coordinator.data:
if self.coordinator.data[self.id]["position"]:
res["speed"] = self.coordinator.data[self.id]["position"][0]["speed"]
res["course"] = self.coordinator.data[self.id]["position"][0][
"direction"
]
res["PDOP"] = self.coordinator.data[self.id]["position"][0]["pdop"]

return res
3 changes: 3 additions & 0 deletions tests/test_device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ async def test_device_tracker(hass):
assert hass.states.get("device_tracker.test").attributes["latitude"] == 47.024191
assert hass.states.get("device_tracker.test").attributes["gps_accuracy"] == 31
assert hass.states.get("device_tracker.test").attributes["icon"] == "mdi:paw"
assert hass.states.get("device_tracker.test").attributes["speed"] == 4.8
assert hass.states.get("device_tracker.test").attributes["course"] == 312
assert hass.states.get("device_tracker.test").attributes["PDOP"] == 99.9


@pytest.mark.usefixtures("get_trackers_not_a_pet_tracker")
Expand Down

0 comments on commit cac4af9

Please sign in to comment.