-
Notifications
You must be signed in to change notification settings - Fork 4
/
device_tracker.py
51 lines (39 loc) · 1.61 KB
/
device_tracker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"""Platform for Tronity device tracker integration."""
from homeassistant.components.device_tracker import SourceType, TrackerEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from .const import DOMAIN, CONF_DATA_COORDINATOR
from . import TronityEntity
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
async_add_entites: AddEntitiesCallback,
) -> None:
"""Set up the device tracker platform."""
coordinator = hass.data[DOMAIN][config_entry.entry_id][CONF_DATA_COORDINATOR]
async_add_entites([TronityDeviceTracker(coordinator, config_entry)])
class TronityDeviceTracker(TronityEntity, TrackerEntity):
"""Class for the device tracker."""
_attr_icon = "mdi:map"
_attr_force_update = False
def __init__(self, coordinator, config_entry) -> None:
"""Initialize Tronity device tracker."""
super().__init__(coordinator, config_entry)
self._attr_unique_id = f"{self.vehicle_id}_device_tracker"
@property
def name(self) -> str:
"""Return name of the sensor."""
return f"{self.vehicle_id}_device_tracker"
@property
def source_type(self) -> SourceType:
"""Return the source type"""
return SourceType.GPS
@property
def latitude(self):
"""Return latitude value of the device."""
return self.coordinator.data["latitude"]
@property
def longitude(self):
"""Return longitude value of the device."""
return self.coordinator.data["longitude"]