Home Assistant Unofficial Reference 2024.12.1
device_tracker.py
Go to the documentation of this file.
1 """StarLine device tracker."""
2 
3 from homeassistant.components.device_tracker import TrackerEntity
4 from homeassistant.config_entries import ConfigEntry
5 from homeassistant.core import HomeAssistant
6 from homeassistant.helpers.entity_platform import AddEntitiesCallback
7 from homeassistant.helpers.restore_state import RestoreEntity
8 
9 from .account import StarlineAccount, StarlineDevice
10 from .const import DOMAIN
11 from .entity import StarlineEntity
12 
13 
15  hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
16 ) -> None:
17  """Set up StarLine entry."""
18  account: StarlineAccount = hass.data[DOMAIN][entry.entry_id]
20  StarlineDeviceTracker(account, device)
21  for device in account.api.devices.values()
22  if device.support_position
23  )
24 
25 
27  """StarLine device tracker."""
28 
29  _attr_translation_key = "location"
30 
31  def __init__(self, account: StarlineAccount, device: StarlineDevice) -> None:
32  """Set up StarLine entity."""
33  super().__init__(account, device, "location")
34 
35  @property
37  """Return device specific attributes."""
38  return self._account_account.gps_attrs(self._device_device)
39 
40  @property
41  def battery_level(self):
42  """Return the battery level of the device."""
43  return self._device_device.battery_level
44 
45  @property
46  def location_accuracy(self):
47  """Return the gps accuracy of the device."""
48  return self._device_device.position.get("r", 0)
49 
50  @property
51  def latitude(self):
52  """Return latitude value of the device."""
53  return self._device_device.position["x"]
54 
55  @property
56  def longitude(self):
57  """Return longitude value of the device."""
58  return self._device_device.position["y"]
None __init__(self, StarlineAccount account, StarlineDevice device)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)