Home Assistant Unofficial Reference 2024.12.1
device_tracker.py
Go to the documentation of this file.
1 """Device Tracker platform for Tessie integration."""
2 
3 from __future__ import annotations
4 
6 from homeassistant.core import HomeAssistant
7 from homeassistant.helpers.entity_platform import AddEntitiesCallback
8 from homeassistant.helpers.typing import StateType
9 
10 from . import TessieConfigEntry
11 from .entity import TessieEntity
12 from .models import TessieVehicleData
13 
14 PARALLEL_UPDATES = 0
15 
16 
18  hass: HomeAssistant,
19  entry: TessieConfigEntry,
20  async_add_entities: AddEntitiesCallback,
21 ) -> None:
22  """Set up the Tessie device tracker platform from a config entry."""
23  data = entry.runtime_data
24 
26  klass(vehicle)
27  for klass in (
28  TessieDeviceTrackerLocationEntity,
29  TessieDeviceTrackerRouteEntity,
30  )
31  for vehicle in data.vehicles
32  )
33 
34 
36  """Base class for Tessie Tracker Entities."""
37 
38  def __init__(
39  self,
40  vehicle: TessieVehicleData,
41  ) -> None:
42  """Initialize the device tracker."""
43  super().__init__(vehicle, self.keykey)
44 
45 
47  """Vehicle Location Device Tracker Class."""
48 
49  key = "location"
50 
51  @property
52  def longitude(self) -> float | None:
53  """Return the longitude of the device tracker."""
54  return self.getget("drive_state_longitude")
55 
56  @property
57  def latitude(self) -> float | None:
58  """Return the latitude of the device tracker."""
59  return self.getget("drive_state_latitude")
60 
61  @property
62  def extra_state_attributes(self) -> dict[str, StateType] | None:
63  """Return device state attributes."""
64  return {
65  "heading": self.getget("drive_state_heading"),
66  "speed": self.getget("drive_state_speed"),
67  }
68 
69 
71  """Vehicle Navigation Device Tracker Class."""
72 
73  key = "route"
74 
75  @property
76  def longitude(self) -> float | None:
77  """Return the longitude of the device tracker."""
78  return self.getget("drive_state_active_route_longitude")
79 
80  @property
81  def latitude(self) -> float | None:
82  """Return the latitude of the device tracker."""
83  return self.getget("drive_state_active_route_latitude")
Any get(self, str|None key=None, Any|None default=None)
Definition: entity.py:52
Definition: config_entry.py:1
None async_setup_entry(HomeAssistant hass, TessieConfigEntry entry, AddEntitiesCallback async_add_entities)