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

Detect device motion #156

Merged
merged 3 commits into from
Nov 1, 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
15 changes: 14 additions & 1 deletion custom_components/myskoda/device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from homeassistant.helpers.typing import DiscoveryInfoType # pyright: ignore [reportAttributeAccessIssue]

from myskoda.models.info import CapabilityId
from myskoda.models.position import Position, Positions, PositionType
from myskoda.models.position import Error, ErrorType, Position, Positions, PositionType

from .const import COORDINATORS, DOMAIN
from .coordinator import MySkodaDataUpdateCoordinator
Expand Down Expand Up @@ -55,6 +55,13 @@ def _vehicle_position(self) -> Position | None:
pos for pos in pos.positions if pos.type == PositionType.VEHICLE
)

def _pos_error(self) -> Error | None:
if pos := self._positions():
if pos.errors:
return next(
err for err in pos.errors if err.type == ErrorType.VEHICLE_IN_MOTION
)

@property
def source_type(self) -> SourceType: # noqa: D102
return SourceType.GPS
Expand Down Expand Up @@ -82,5 +89,11 @@ def extra_state_attributes(self) -> dict:

return attributes

@property
def location_name(self) -> str | None:
if err := self._pos_error():
if err.type == ErrorType.VEHICLE_IN_MOTION:
return "vehicle_in_motion"

def required_capabilities(self) -> list[CapabilityId]:
return [CapabilityId.PARKING_POSITION]
7 changes: 6 additions & 1 deletion custom_components/myskoda/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,12 @@
},
"device_tracker": {
"device_tracker": {
"name": "Positition"
"name": "Position",
"state": {
"vehicle_in_motion": "Motion detected",
"not_home": "Away",
"home": "Home"
}
}
},
"number": {
Expand Down