1 """Device tracker for Mobile app."""
27 ATTR_VERTICAL_ACCURACY,
28 SIGNAL_LOCATION_UPDATE,
30 from .helpers
import device_info
32 ATTR_KEYS = (ATTR_ALTITUDE, ATTR_COURSE, ATTR_SPEED, ATTR_VERTICAL_ACCURACY)
36 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
38 """Set up Mobile app based off an entry."""
44 """Represent a tracked device."""
47 """Set up Mobile app entity."""
54 """Return the unique ID."""
55 return self.
_entry_entry.data[ATTR_DEVICE_ID]
59 """Return the battery level of the device."""
60 return self.
_data_data.
get(ATTR_BATTERY)
64 """Return device specific attributes."""
67 if (value := self.
_data_data.
get(key))
is not None:
74 """Return the gps accuracy of the device."""
75 return self.
_data_data.
get(ATTR_GPS_ACCURACY)
79 """Return latitude value of the device."""
80 if (gps := self.
_data_data.
get(ATTR_GPS))
is None:
87 """Return longitude value of the device."""
88 if (gps := self.
_data_data.
get(ATTR_GPS))
is None:
95 """Return a location name for the current location of the device."""
96 if location_name := self.
_data_data.
get(ATTR_LOCATION_NAME):
102 """Return the name of the device."""
103 return self.
_entry_entry.data[ATTR_DEVICE_NAME]
107 """Return the device info."""
111 """Call when entity about to be added to Home Assistant."""
115 SIGNAL_LOCATION_UPDATE.format(self.
_entry_entry.entry_id),
120 if self.
_data_data
is not None:
127 attr = state.attributes
129 ATTR_GPS: (attr.get(ATTR_LATITUDE), attr.get(ATTR_LONGITUDE)),
130 ATTR_GPS_ACCURACY: attr.get(ATTR_GPS_ACCURACY),
131 ATTR_BATTERY: attr.get(ATTR_BATTERY_LEVEL),
133 data.update({key: attr[key]
for key
in attr
if key
in ATTR_KEYS})
134 self.
_data_data = data
137 """Call when entity is being removed from hass."""
146 """Mark the device as seen."""
147 self.
_data_data = data
None async_added_to_hass(self)
def extra_state_attributes(self)
def __init__(self, entry, data=None)
def update_data(self, data)
def location_accuracy(self)
None async_will_remove_from_hass(self)
None async_write_ha_state(self)
State|None async_get_last_state(self)
web.Response get(self, web.Request request, str config_key)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)