Google Maps location sharing

I bumped to 2.0.2 and have no error now. Doesn’t seem to work tho because I don’t see any updates of device trackers. I’ll wait some more and report back (if there will be error I’ll open issue on github :slight_smile: )
Thx :slight_smile:

Hi all,

Sorry if this was already answered. But would a google ‘App password’ work for this?
https://myaccount.google.com/apppasswords

Cheers

Edit: As I posted this I noticed the ‘similar post’ message on the right hand side of the screen, sorry!

Looks like hassio with 0.68.1 is still using

locationsharinglib-1.2.1-py3.6.egg-info/

Facing this issue outside of hassio with get-maps-cookies -https://github.com/costastf/locationsharinglib/issues/22

A usage question, within homeassistant with 2FA enabled, how is the challenge handled given it’s only u/p in the config and the rest is in the background.

How fix cookie error?

Hi all

I’m getting no update, just after restarting Hassio.
I’m running on 0.69.1 (was the same with 0.69) on RPi 3 B

I get these error messages in the log

2018-05-13 14:24:50 ERROR (MainThread) [homeassistant.components.device_tracker] Error setting up platform google_maps
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/homeassistant/components/device_tracker/__init__.py", line 184, in async_setup_platform
    disc_info)
  File "/usr/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/lib/python3.6/site-packages/homeassistant/components/device_tracker/google_maps.py", line 36, in setup_scanner
    scanner = GoogleMapsScanner(hass, config, see)
  File "/usr/lib/python3.6/site-packages/homeassistant/components/device_tracker/google_maps.py", line 55, in __init__
    self._update_info()
  File "/usr/lib/python3.6/site-packages/homeassistant/components/device_tracker/google_maps.py", line 68, in _update_info
    dev_id = 'google_maps_{0}'.format(slugify(person.id))
  File "/usr/lib/python3.6/site-packages/homeassistant/util/__init__.py", line 43, in slugify
    text = normalize('NFKD', text)
TypeError: normalize() argument 2 must be str, not None

Any advice?

Thanks

Maybe I’m saying too obvious things, but have you tried deleting the .google_maps_location_sharing.cookies file and restarting the Home Assistant? This file is hidden and located in the folder config

Yes, I’ve tried several times to remove the .google_maps_location_sharing.cookies file in the config folder.
When I do, I get the security alert mail from google and it does update just after restarting Hass.io. Then no more updates.
If I just restart Hass.io, I get an update (no security mail) and then no more.

same behaviour here on a non-hassio rpi setup v.0.69

same for me, hassio rpi v0.69.1

Confirmed same behaviour. HA 0.69.1

lets make sure to get the new error posted in github for this project:

@costas I use this component for several days. It works fine, but sometimes the location is read with rather low accuracy (up to 3128 meters). I read in this thread that the component previously allowed to set the accuracy threshold, but now I see only two variables in the component description: username and password.
Is there any way to filter the location with an accuracy of more than 150 meters?

It seems like the person.id is blank when it is the location of the account that is being used that is sent back. I changed line 68 of “google_maps.py” to read:

dev_id = ‘google_maps_{0}’.format(slugify(person.id if person.id is not None else ‘Patrick’))

Where Patrick is the account holder’s name.

v2.0.7 of the underlying library should fix that for you @Patrick123. In place of the missing ID you will get the email of the account.

@Yevgeniy I am actually on an old HA version so still using a custom component, which indeed has a fix for accuracy. Don’t really remember where I got it exactly from but here it is…

"""
Support for Google Maps location sharing.

For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/device_tracker.google_maps/
"""
import logging
from datetime import timedelta

import voluptuous as vol

import homeassistant.helpers.config_validation as cv
from homeassistant.components.device_tracker import (
   PLATFORM_SCHEMA, SOURCE_TYPE_GPS)
from homeassistant.const import CONF_USERNAME, CONF_PASSWORD
from homeassistant.helpers.event import track_time_interval
from homeassistant.helpers.typing import ConfigType
from homeassistant.util import slugify

_LOGGER = logging.getLogger(__name__)

REQUIREMENTS = ['locationsharinglib==1.2.1']

CONF_MAX_GPS_ACCURACY = 'max_gps_accuracy'
CREDENTIALS_FILE = '.google_maps_location_sharing.cookies'

MIN_TIME_BETWEEN_SCANS = timedelta(seconds=30)

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
   vol.Required(CONF_USERNAME): cv.string,
   vol.Required(CONF_PASSWORD): cv.string,
   vol.Optional(CONF_MAX_GPS_ACCURACY): vol.Coerce(float),
})


def setup_scanner(hass, config: ConfigType, see, discovery_info=None):
   """Set up the scanner."""
   scanner = GoogleMapsScanner(hass, config, see)
   return scanner.success_init


class GoogleMapsScanner(object):
   """Representation of an Google Maps location sharing account."""

   def __init__(self, hass, config: ConfigType, see) -> None:
       """Initialize the scanner."""
       from locationsharinglib import Service
       from locationsharinglib.locationsharinglibexceptions import InvalidUser

       self.see = see
       self.username = config[CONF_USERNAME]
       self.password = config[CONF_PASSWORD]
       self.max_gps_accuracy = config[CONF_MAX_GPS_ACCURACY]

       try:
           self.service = Service(self.username, self.password,
                                  hass.config.path(CREDENTIALS_FILE))
           self._update_info()

           track_time_interval(
               hass, self._update_info, MIN_TIME_BETWEEN_SCANS)

           self.success_init = True

       except InvalidUser:
           _LOGGER.error('You have specified invalid login credentials')
           self.success_init = False

   def _update_info(self, now=None):
       for person in self.service.get_all_people():
           dev_id = 'google_maps_{0}'.format(slugify(person.id))

           if self.max_gps_accuracy is not None and \
                   person.accuracy > self.max_gps_accuracy:
               _LOGGER.info("Ignoring update because expected GPS "
                            "accuracy %s is not met: %s",
                            self.max_gps_accuracy, person.accuracy)
               continue

           attrs = {
               'id': person.id,
               'nickname': person.nickname,
               'full_name': person.full_name,
               'last_seen': person.datetime,
               'address': person.address
           }
           self.see(
               dev_id=dev_id,
               gps=(person.latitude, person.longitude),
               picture=person.picture_url,
               source_type=SOURCE_TYPE_GPS,
               attributes=attrs
           )

Please update the version of the underlying library to the latest version.

For everyone having issues with random lock outs from google please use the latest version and report on the issue tracker of the library until we get all of the issues fixed.

FYI
I’ve updated to 2.0.7 (by editing homeassistant/components/device_tracker/google_maps.py) and so far no errors and HA picks up data correctly :slight_smile:

I will close this thread. It was create for the feature.

Please open a new thread in Configuration or report issue in the tracker. Thanks