Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add speed and heading attributes to location sensor #57

Merged
merged 4 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.2
Loading