hass-core/homeassistant/components/starline/device_tracker.py
Nikolay Vasilchuk a37260faa9 StarLine integration (#27197)
* Device Tracker works

* Device Tracker works

* Binary Sensor

* Sensor

* Lock

* Switch and service

* New switches

* Update interval options

* WIP

* Translation errors

* Check online state

* WIP

* Move to aiohttp

* Some checks

* CI

* CI

* .coveragerc

* Black

* icon_for_signal_level test

* update_interval renamed to scan_interval

* async logic

* Fix cookie read

* Requirement starline

* Reformat

* Requirements updated

* ConfigEntryNotReady

* Requirement starline

* Lint fix

* Requirement starline

* available status

* Translations

* Expiration to config

* CI

* Linter fix

* Small renaming

* Update slnet token

* Starline version bump

* Fix updates

* Black

* Small fix

* Removed unused fields

* CI

* set_scan_interval service

* deps updated

* Horn switch

* Starline lib updated

* Starline lib updated

* Black

* Support multiple integrations

* Review

* async_will_remove_from_hass

* Deps updated

* Test config flow

* Requirements

* CI

* Review

* Review

* Review

* Review

* Review

* CI

* pylint fix

* Review

* Support "mayak" devices

* Icons removed

* Removed options_flow

* Removed options_flow test

* Removed options_flow test
2019-11-26 11:17:11 -08:00

60 lines
2 KiB
Python

"""StarLine device tracker."""
from homeassistant.components.device_tracker.config_entry import TrackerEntity
from homeassistant.components.device_tracker.const import SOURCE_TYPE_GPS
from homeassistant.helpers.restore_state import RestoreEntity
from .account import StarlineAccount, StarlineDevice
from .const import DOMAIN
from .entity import StarlineEntity
async def async_setup_entry(hass, entry, async_add_entities):
"""Set up StarLine entry."""
account: StarlineAccount = hass.data[DOMAIN][entry.entry_id]
entities = []
for device in account.api.devices.values():
if device.support_position:
entities.append(StarlineDeviceTracker(account, device))
async_add_entities(entities)
class StarlineDeviceTracker(StarlineEntity, TrackerEntity, RestoreEntity):
"""StarLine device tracker."""
def __init__(self, account: StarlineAccount, device: StarlineDevice):
"""Set up StarLine entity."""
super().__init__(account, device, "location", "Location")
@property
def device_state_attributes(self):
"""Return device specific attributes."""
return self._account.gps_attrs(self._device)
@property
def battery_level(self):
"""Return the battery level of the device."""
return self._device.battery_level
@property
def location_accuracy(self):
"""Return the gps accuracy of the device."""
return self._device.position["r"] if "r" in self._device.position else 0
@property
def latitude(self):
"""Return latitude value of the device."""
return self._device.position["x"]
@property
def longitude(self):
"""Return longitude value of the device."""
return self._device.position["y"]
@property
def source_type(self):
"""Return the source type, eg gps or router, of the device."""
return SOURCE_TYPE_GPS
@property
def icon(self):
"""Return the icon to use in the frontend, if any."""
return "mdi:map-marker-outline"