-
-
Notifications
You must be signed in to change notification settings - Fork 30k
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
Conversation
}) | ||
|
||
|
||
def setup_scanner(hass, config: dict, see, discovery_info=None): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm no expert, but this seems more like a debug
log entry to me.
|
||
REQUIREMENTS = ['locationsharinglib==0.3.0'] | ||
|
||
CONF_IGNORED_DEVICES = 'ignored_devices' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it somehow possible to change these identifiers in for example the entity registry? (cc @balloob)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of scope 😉
I think that we should be able to use this ID as a unique ID inside the device tracker.
Does this needs changing anything? |
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. |
won't the entity_registry let us rename the entities created with a unique id? really looking forward to this integration getting added :) |
@Esiravegna Slightly off-topic, but even without the entity registry you can already influence the 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. |
@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' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a .
in front of the name
hass.config.path(CREDENTIALS_FILE)) | ||
self._update_info() | ||
|
||
track_utc_time_change( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems you just want to call track_time_interval(hass, action, interval)
attributes=attrs | ||
) | ||
|
||
return True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nothing is checking this return value.
from locationsharinglib import Service | ||
from locationsharinglib.locationsharinglibexceptions import InvalidUser | ||
|
||
self.hass = hass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove period at the end.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
@MartinHjelmare i've addressed your remarks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
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 ❤️ |
I have this error in /config/.google_maps_location_sharing.cookies |
Please open an issue if you suspect a bug. If you need help please use our help channels: Merged PRs should not be used for support or bug reports. Thanks! |
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):Checklist:
If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
tox
run successfully. Your PR cannot be merged unless tests passREQUIREMENTS
variable (example).requirements_all.txt
by runningscript/gen_requirements_all.py
..coveragerc
.If the code does not interact with devices:
tox
run successfully. Your PR cannot be merged unless tests pass