diff --git a/custom_components/myskoda/device_tracker.py b/custom_components/myskoda/device_tracker.py index 4cf6f23..513e672 100644 --- a/custom_components/myskoda/device_tracker.py +++ b/custom_components/myskoda/device_tracker.py @@ -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 @@ -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 @@ -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] diff --git a/custom_components/myskoda/translations/en.json b/custom_components/myskoda/translations/en.json index 396b9e6..9d1adb1 100644 --- a/custom_components/myskoda/translations/en.json +++ b/custom_components/myskoda/translations/en.json @@ -97,7 +97,12 @@ }, "device_tracker": { "device_tracker": { - "name": "Positition" + "name": "Position", + "state": { + "vehicle_in_motion": "Motion detected", + "not_home": "Away", + "home": "Home" + } } }, "number": {