Hi all. New to HA (I’ve been using SmartThings for a while, but am in the process of moving to HA) and, of course, this forum. But after searching around a bit, and reading through this topic, I thought I’d prefer to have a more direct integration that doesn’t rely on MQTT or shell scripts.
I found this: https://github.com/harperreed/life360-python. I know it’s probably not “complete”, and it isn’t a PyPI package, but it was a start. I grabbed a copy and then wrote this Device Tracker platform (which I also named life360.py, hence the renaming of the other script to pylife360.py):
import logging
import voluptuous as vol
from homeassistant.components.device_tracker import (
PLATFORM_SCHEMA, CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL)
from homeassistant.const import CONF_USERNAME, CONF_PASSWORD
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.event import track_point_in_utc_time
from homeassistant import util
_LOGGER = logging.getLogger(__name__)
_AUTHORIZATION_TOKEN = "cFJFcXVnYWJSZXRyZTRFc3RldGhlcnVmcmVQdW1hbUV4dWNyRUh1YzptM2ZydXBSZXRSZXN3ZXJFQ2hBUHJFOTZxYWtFZHI0Vg=="
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_USERNAME): cv.string,
vol.Required(CONF_PASSWORD): cv.string
})
def setup_scanner(hass, config, see, discovery_info=None):
from pylife360 import life360
try:
api = life360(_AUTHORIZATION_TOKEN, config[CONF_USERNAME], config[CONF_PASSWORD])
if api.authenticate():
circle_id = api.get_circles()[0]['id']
else:
raise
except:
_LOGGER.error("Life360 authentication failed!")
return False
_LOGGER.info("Life360 authentication successful!")
interval = config.get(CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL)
Life360Scanner(hass, see, interval, api, circle_id)
return True
class Life360Scanner(object):
def __init__(self, hass, see, interval, api, circle_id):
self._hass = hass
self._see = see
self._interval = interval
self._api = api
self._circle_id = circle_id
self._update_life360()
def _update_life360(self, now=None):
try:
circle = self._api.get_circle(self._circle_id)
for m in circle['members']:
loc = m['location']
lat = float(loc['latitude'])
lon = float(loc['longitude'])
name = " ".join([m['firstName'], m['lastName']])
attrs = {
'friendly_name': name
}
self._see(dev_id=util.slugify(name), location_name=loc['name'],
gps=(lat, lon), gps_accuracy=round(float(loc['accuracy'])),
battery=int(loc['battery']), attributes=attrs)
finally:
track_point_in_utc_time(self._hass, self._update_life360,
util.dt.utcnow() + self._interval)
Seems to work ok for me and my small Circle. Looking for any feedback, good or bad, and generally, what you think about the approach.