New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google Maps location sharing device tracker. #12301

Merged
merged 7 commits into from Mar 30, 2018

Conversation

@michaelarnauts
Contributor

michaelarnauts commented Feb 11, 2018

Description:

This component uses Google Maps location sharing to track device location. This allows to track android devices without battery impact or having to install another app.

Uses https://github.com/costastf/locationsharinglib to fetch the locations of shared accounts.

Documentation is available at: home-assistant/home-assistant.io#4646

Example entry for configuration.yaml (if applicable):

device_tracker:
  - platform: google_maps
    username: username@gmail.com
    password: password

Checklist:

  • The code change is tested and works locally.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • Local tests with tox run successfully. Your PR cannot be merged unless tests pass
  • New dependencies have been added to the REQUIREMENTS variable (example).
  • New dependencies are only imported inside functions that use them (example).
  • New dependencies have been added to requirements_all.txt by running script/gen_requirements_all.py.
  • New files were added to .coveragerc.

If the code does not interact with devices:

  • Local tests with tox run successfully. Your PR cannot be merged unless tests pass
  • Tests have been added to verify that the new code works.

@michaelarnauts michaelarnauts requested a review from andrey-git as a code owner Feb 11, 2018

@michaelarnauts michaelarnauts changed the title from Google Maps location sharing device tracker. to WIP: Google Maps location sharing device tracker. Feb 11, 2018

})
def setup_scanner(hass, config: dict, see, discovery_info=None):

This comment has been minimized.

@OttoWinter

OttoWinter Feb 11, 2018

Contributor

There's a special ConfigType in helpers/typing that should probably be used instead of dict.

try:
# Check if we already have cached credentials
if os.path.isfile(CREDENTIALS_FILE):
_LOGGER.info('Authenticating with credentials file.')

This comment has been minimized.

@OttoWinter

OttoWinter Feb 11, 2018

Contributor

I'm no expert, but this seems more like a debug log entry to me.

@michaelarnauts michaelarnauts changed the title from WIP: Google Maps location sharing device tracker. to Google Maps location sharing device tracker. Feb 12, 2018

REQUIREMENTS = ['locationsharinglib==0.3.0']
CONF_IGNORED_DEVICES = 'ignored_devices'

This comment has been minimized.

@michaelarnauts

michaelarnauts Feb 14, 2018

Contributor

Just noticed these two are not used. I will remove them.

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

This comment has been minimized.

@jurriaan

jurriaan Feb 17, 2018

Is it somehow possible to change these identifiers in for example the entity registry? (cc @balloob)

This comment has been minimized.

@balloob

balloob Feb 18, 2018

Member

Out of scope 😉

I think that we should be able to use this ID as a unique ID inside the device tracker.

@michaelarnauts

This comment has been minimized.

Contributor

michaelarnauts commented Feb 24, 2018

Does this needs changing anything?

@Esiravegna

This comment has been minimized.

Esiravegna commented Feb 26, 2018

THing is, if we can use the ID as an internal tracker (check the MAC address for the router based tracking), we could name the device in a sensible way (my_phone, wife_phone, etc) as opposed to the current names required in know_devices.yaml, that are hard to remember.

@dshokouhi

This comment has been minimized.

Contributor

dshokouhi commented Feb 26, 2018

won't the entity_registry let us rename the entities created with a unique id? really looking forward to this integration getting added :)

@fanaticDavid

This comment has been minimized.

Contributor

fanaticDavid commented Feb 27, 2018

@Esiravegna Slightly off-topic, but even without the entity registry you can already influence the entity_id of the devices in the known_devices.yaml file:

001710xxxxxx:               => changing this to abc will change the entity_id from device_tracker.001710xxxxxx to device_tracker.abc
  hide_if_away: false
  icon:
  mac: 00:17:10:xx:xx:xx
  name: 001710xxxxxx        => this is used as the device's friendly_name in the UI
  picture:
  track: false
  vendor: Casa Systems Inc.

Changes are applied after restarting Home Assistant.
@Esiravegna

This comment has been minimized.

Esiravegna commented Feb 27, 2018

@fanaticDavid Thanks I'm aware of that. Thing is, somewhere in the structure the id generated by this component must reside, otherwise the tracking will not be there. I don't think is the MAC here, and if it is, problem is that the router presence detector also uses them, and thus we won't be able to use both methods.

TL;DR: I'd like to see a way to rename the device, keeping the google maps id and also use the other presence detectors, hence muy point.

REQUIREMENTS = ['locationsharinglib==0.3.0']
CREDENTIALS_FILE = 'google_maps_location_sharing.conf'

This comment has been minimized.

@balloob

balloob Mar 1, 2018

Member

Please add a . in front of the name

hass.config.path(CREDENTIALS_FILE))
self._update_info()
track_utc_time_change(

This comment has been minimized.

@balloob

balloob Mar 1, 2018

Member

It seems you just want to call track_time_interval(hass, action, interval)

attributes=attrs
)
return True

This comment has been minimized.

@MartinHjelmare

MartinHjelmare Mar 2, 2018

Member

Nothing is checking this return value.

from locationsharinglib import Service
from locationsharinglib.locationsharinglibexceptions import InvalidUser
self.hass = hass

This comment has been minimized.

@MartinHjelmare

MartinHjelmare Mar 2, 2018

Member

Nothing is using the instance attribute outside this method. Please remove the attribute and just use hass locally in this method.

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

This comment has been minimized.

@MartinHjelmare

MartinHjelmare Mar 2, 2018

Member

Remove period at the end.

This comment has been minimized.

@costastf

costastf Mar 4, 2018

I have updated locationsharinglib to 0.4.0 fixing a bug with single quotes of the json payload and exposing gps accuracy as an attribute. The dependency should be updated to this version. I also suggest to change the .conf extension to the more semantically correct .cookies

This comment has been minimized.

@michaelarnauts

michaelarnauts Mar 5, 2018

Contributor

GPS accuracy is not fetched from the correct field. I get an accuracy of 1500 when google maps locates me spot on with no blue accuract circle. I've not included this information.

@michaelarnauts

This comment has been minimized.

Contributor

michaelarnauts commented Mar 17, 2018

@MartinHjelmare i've addressed your remarks.
@andrey-git do you need to review this?

@MartinHjelmare

Just a minor comment for clarity.

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

This comment has been minimized.

@MartinHjelmare

MartinHjelmare Mar 18, 2018

Member

setup_scanner doesn't want the scanner instance, it just wants a boolean, where true means successful platform setup.

This will work, but it's less clear.

This comment has been minimized.

@michaelarnauts

michaelarnauts Mar 30, 2018

Contributor

A lot of device_tracker platforms seem to do exactly this. I don't think this is blocking the merge of this component? Anyway, I will make the change...

homeassistant/components/device_tracker/actiontec.py:    return scanner if scanner.success_init else None
homeassistant/components/device_tracker/aruba.py:    return scanner if scanner.success_init else None
homeassistant/components/device_tracker/asuswrt.py:    return scanner if scanner.success_init else None
homeassistant/components/device_tracker/bbox.py:    return scanner if scanner.success_init else None
homeassistant/components/device_tracker/bt_home_hub_5.py:    return scanner if scanner.success_init else None
homeassistant/components/device_tracker/cisco_ios.py:    return scanner if scanner.success_init else None
homeassistant/components/device_tracker/fritz.py:    return scanner if scanner.success_init else None
homeassistant/components/device_tracker/google_maps.py:    return scanner if scanner.success_init else None
homeassistant/components/device_tracker/hitron_coda.py:    return scanner if scanner.success_init else None
homeassistant/components/device_tracker/keenetic_ndms2.py:    return scanner if scanner.success_init else None
homeassistant/components/device_tracker/luci.py:    return scanner if scanner.success_init else None
homeassistant/components/device_tracker/mikrotik.py:    return scanner if scanner.success_init else None
homeassistant/components/device_tracker/netgear.py:    return scanner if scanner.success_init else None
homeassistant/components/device_tracker/nmap_tracker.py:    return scanner if scanner.success_init else None
homeassistant/components/device_tracker/sky_hub.py:    return scanner if scanner.success_init else None
homeassistant/components/device_tracker/snmp.py:    return scanner if scanner.success_init else None
homeassistant/components/device_tracker/swisscom.py:    return scanner if scanner.success_init else None
homeassistant/components/device_tracker/tado.py:    return scanner if scanner.success_init else None
homeassistant/components/device_tracker/thomson.py:    return scanner if scanner.success_init else None
homeassistant/components/device_tracker/ubus.py:    return scanner if scanner.success_init else None
homeassistant/components/device_tracker/xiaomi.py:    return scanner if scanner.success_init else None

This comment has been minimized.

@MartinHjelmare

MartinHjelmare Mar 30, 2018

Member

get_scanner should return the scanner instance but not setup_scanner. Platforms that use that latter should not behave like platforms that use the former.

@MartinHjelmare

Thanks!

@MartinHjelmare MartinHjelmare merged commit 0f24fea into dev Mar 30, 2018

6 checks passed

WIP ready for review
Details
cla-bot Everyone involved has signed the CLA
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
coverage/coveralls Coverage decreased (-0.02%) to 93.953%
Details
hound No violations found. Woof!

@Danielhiversen Danielhiversen deleted the google_maps_device_tracker branch Apr 4, 2018

@disrupted

This comment has been minimized.

disrupted commented Apr 7, 2018

this is awesome ! I was only just tweeting the other day how much I would love a Google location history device tracker and here it is already, gotta love this community ❤️

@proximus-983

This comment has been minimized.

proximus-983 commented Apr 9, 2018

I have this error in /config/.google_maps_location_sharing.cookies
'utf-8' codec can't decode byte 0x80 in position 0: invalid start byte
and no device appears in known_devices.yaml

@home-assistant home-assistant locked and limited conversation to collaborators Apr 9, 2018

@MartinHjelmare

This comment has been minimized.

Member

MartinHjelmare commented Apr 9, 2018

Please open an issue if you suspect a bug. If you need help please use our help channels:
https://home-assistant.io/help/#communication-channels

Merged PRs should not be used for support or bug reports. Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.