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

Fix unavailable device tracker #11

Merged
merged 2 commits into from
Sep 21, 2024
Merged
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
19 changes: 16 additions & 3 deletions custom_components/myskoda/device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import DiscoveryInfoType
from myskoda.models.info import CapabilityId
from myskoda.models.position import Positions
from myskoda.models.position import Position, PositionType, Positions

from .const import COORDINATOR, DOMAIN
from .coordinator import MySkodaDataUpdateCoordinator
Expand Down Expand Up @@ -50,17 +50,30 @@ def _positions(self) -> Positions:
)
return positions

def _vehicle_position(self) -> Position | None:
return next(
pos
for pos in self._positions().positions
if pos.type == PositionType.VEHICLE
)

@property
def source_type(self) -> SourceType: # noqa: D102
return SourceType.GPS

@property
def latitude(self) -> float | None: # noqa: D102
return self._positions().positions[0].gps_coordinates.latitude
position = self._vehicle_position()
if position is None:
return None
return position.gps_coordinates.latitude

@property
def longitude(self) -> float | None: # noqa: D102
return self._positions().positions[0].gps_coordinates.longitude
position = self._vehicle_position()
if position is None:
return None
return position.gps_coordinates.longitude

def required_capabilities(self) -> list[CapabilityId]:
return [CapabilityId.PARKING_POSITION]
Loading