Support for TrackR device trackers (#5010)
* Support for TrackR device trackers * Change small style for hass
This commit is contained in:
parent
d12decc471
commit
f7a1d63d52
3 changed files with 83 additions and 0 deletions
|
@ -169,6 +169,7 @@ omit =
|
|||
homeassistant/components/device_tracker/thomson.py
|
||||
homeassistant/components/device_tracker/tomato.py
|
||||
homeassistant/components/device_tracker/tplink.py
|
||||
homeassistant/components/device_tracker/trackr.py
|
||||
homeassistant/components/device_tracker/ubus.py
|
||||
homeassistant/components/device_tracker/volvooncall.py
|
||||
homeassistant/components/discovery.py
|
||||
|
|
79
homeassistant/components/device_tracker/trackr.py
Normal file
79
homeassistant/components/device_tracker/trackr.py
Normal file
|
@ -0,0 +1,79 @@
|
|||
"""
|
||||
Support for the TrackR platform.
|
||||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/device_tracker.trackr/
|
||||
"""
|
||||
import logging
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.device_tracker import PLATFORM_SCHEMA
|
||||
from homeassistant.const import CONF_USERNAME, CONF_PASSWORD
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.event import track_utc_time_change
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
REQUIREMENTS = ['pytrackr==0.0.5']
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||
vol.Required(CONF_USERNAME): cv.string,
|
||||
vol.Required(CONF_PASSWORD): cv.string
|
||||
})
|
||||
|
||||
|
||||
def setup_scanner(hass, config: dict, see):
|
||||
"""Validate the configuration and return a TrackR scanner."""
|
||||
TrackRDeviceScanner(hass, config, see)
|
||||
return True
|
||||
|
||||
|
||||
class TrackRDeviceScanner(object):
|
||||
"""A class representing a TrackR device."""
|
||||
|
||||
def __init__(self, hass, config: dict, see) -> None:
|
||||
"""Initialize the TrackR device scanner."""
|
||||
from pytrackr.api import trackrApiInterface
|
||||
self.hass = hass
|
||||
self.api = trackrApiInterface(config.get(CONF_USERNAME),
|
||||
config.get(CONF_PASSWORD))
|
||||
self.see = see
|
||||
self.devices = self.api.get_trackrs()
|
||||
self._update_info()
|
||||
|
||||
track_utc_time_change(self.hass, self._update_info,
|
||||
second=range(0, 60, 30))
|
||||
|
||||
def _update_info(self, now=None) -> None:
|
||||
"""Update the device info."""
|
||||
_LOGGER.debug('Updating devices %s', now)
|
||||
|
||||
# Update self.devices to collect new devices added
|
||||
# to the users account.
|
||||
self.devices = self.api.get_trackrs()
|
||||
|
||||
for trackr in self.devices:
|
||||
trackr.update_state()
|
||||
trackr_id = trackr.tracker_id()
|
||||
trackr_device_id = trackr.id()
|
||||
lost = trackr.lost()
|
||||
dev_id = trackr.name().replace(" ", "_")
|
||||
if dev_id is None:
|
||||
dev_id = trackr_id
|
||||
location = trackr.last_known_location()
|
||||
lat = location['latitude']
|
||||
lon = location['longitude']
|
||||
|
||||
attrs = {
|
||||
'last_updated': trackr.last_updated(),
|
||||
'last_seen': trackr.last_time_seen(),
|
||||
'trackr_id': trackr_id,
|
||||
'id': trackr_device_id,
|
||||
'lost': lost,
|
||||
'battery_level': trackr.battery_level()
|
||||
}
|
||||
|
||||
self.see(
|
||||
dev_id=dev_id, gps=(lat, lon), attributes=attrs
|
||||
)
|
|
@ -514,6 +514,9 @@ python-vlc==1.1.2
|
|||
# homeassistant.components.wink
|
||||
python-wink==0.11.0
|
||||
|
||||
# homeassistant.components.device_tracker.trackr
|
||||
pytrackr==0.0.5
|
||||
|
||||
# homeassistant.components.device_tracker.unifi
|
||||
pyunifi==1.3
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue