Skip to content

Commit

Permalink
Fix unavailable device tracker (#11)
Browse files Browse the repository at this point in the history
* Fix unavailable device tracker causing exceptions

* Use only vehicle position entity

---------

Co-authored-by: Frederick Gnodtke <[email protected]>
  • Loading branch information
WebSpider and Prior99 authored Sep 21, 2024
1 parent 6d8ddb8 commit 60871ed
Showing 1 changed file with 16 additions and 3 deletions.
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]

0 comments on commit 60871ed

Please sign in to comment.