Skip to content

Commit

Permalink
Merge pull request #57 from MTrab:Add-speed-and-heading-attributes-to…
Browse files Browse the repository at this point in the history
…-location-sensor

Add speed and heading attributes to location sensor
  • Loading branch information
MTrab committed Mar 29, 2024
2 parents 6779ed7 + 56f5828 commit aaa2c75
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
2 changes: 2 additions & 0 deletions custom_components/webastoconnect/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@
NEW_DATA = "webasto_signal"

ATTR_COORDINATOR = "updatecoordinator"
ATTR_SPEED = "speed"
ATTR_DIRECTION = "direction"
18 changes: 17 additions & 1 deletion custom_components/webastoconnect/device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from homeassistant.util import slugify as util_slugify

from .api import WebastoConnectUpdateCoordinator
from .const import ATTR_COORDINATOR, DOMAIN
from .const import ATTR_COORDINATOR, ATTR_DIRECTION, ATTR_SPEED, DOMAIN

LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -75,6 +75,16 @@ def __init__(
util_slugify(f"{self.coordinator.cloud.name} {self._attr_name}")
)

self._attributes = {
ATTR_DIRECTION: self.coordinator.cloud.heading,
ATTR_SPEED: self.coordinator.cloud.speed,
}

@property
def extra_state_attributes(self):
"""Return device specific attributes."""
return self._attributes

@property
def available(self) -> bool:
"""Handle the location states."""
Expand All @@ -94,6 +104,12 @@ def _handle_coordinator_update(self) -> None:
):
self._prev_lat = self.coordinator.cloud.location["lat"]
self._prev_lon = self.coordinator.cloud.location["lon"]

self._attributes = {
ATTR_DIRECTION: self.coordinator.cloud.heading,
ATTR_SPEED: self.coordinator.cloud.speed,
}

self.async_write_ha_state()

@property
Expand Down
2 changes: 1 addition & 1 deletion custom_components/webastoconnect/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/MTrab/webastoconnect/issues",
"requirements": [
"pywebasto==1.0.0"
"pywebasto==1.0.3"
],
"version": "0.2.0"
}
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
colorlog==6.8.2
homeassistant==2024.2.2
homeassistant==2024.3.2
pip>=21.0,<24.1
ruff==0.3.4

0 comments on commit aaa2c75

Please sign in to comment.