Update Google Maps Location Tracker to use locationsharinglib==4.0.2 (#25316)
* Update google_maps: Bump locationsharinglib to 4.0.2 * Remove unused import. * Corrections based on review.pull/25362/head
parent
fc5b1c7005
commit
83581be4d5
|
@ -2,17 +2,19 @@
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from locationsharinglib import Service
|
||||||
|
from locationsharinglib.locationsharinglibexceptions import InvalidCookies
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.device_tracker import (
|
from homeassistant.components.device_tracker import (
|
||||||
PLATFORM_SCHEMA, SOURCE_TYPE_GPS)
|
PLATFORM_SCHEMA, SOURCE_TYPE_GPS)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_ID, CONF_PASSWORD, CONF_USERNAME, ATTR_BATTERY_CHARGING,
|
ATTR_BATTERY_CHARGING, ATTR_BATTERY_LEVEL, ATTR_ID, CONF_SCAN_INTERVAL,
|
||||||
ATTR_BATTERY_LEVEL)
|
CONF_USERNAME)
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.event import track_time_interval
|
from homeassistant.helpers.event import track_time_interval
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
from homeassistant.util import slugify, dt as dt_util
|
from homeassistant.util import dt as dt_util, slugify
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -25,10 +27,7 @@ CONF_MAX_GPS_ACCURACY = 'max_gps_accuracy'
|
||||||
|
|
||||||
CREDENTIALS_FILE = '.google_maps_location_sharing.cookies'
|
CREDENTIALS_FILE = '.google_maps_location_sharing.cookies'
|
||||||
|
|
||||||
MIN_TIME_BETWEEN_SCANS = timedelta(seconds=30)
|
|
||||||
|
|
||||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||||
vol.Required(CONF_PASSWORD): cv.string,
|
|
||||||
vol.Required(CONF_USERNAME): cv.string,
|
vol.Required(CONF_USERNAME): cv.string,
|
||||||
vol.Optional(CONF_MAX_GPS_ACCURACY, default=100000): vol.Coerce(float),
|
vol.Optional(CONF_MAX_GPS_ACCURACY, default=100000): vol.Coerce(float),
|
||||||
})
|
})
|
||||||
|
@ -45,27 +44,27 @@ class GoogleMapsScanner:
|
||||||
|
|
||||||
def __init__(self, hass, config: ConfigType, see) -> None:
|
def __init__(self, hass, config: ConfigType, see) -> None:
|
||||||
"""Initialize the scanner."""
|
"""Initialize the scanner."""
|
||||||
from locationsharinglib import Service
|
|
||||||
from locationsharinglib.locationsharinglibexceptions import InvalidUser
|
|
||||||
|
|
||||||
self.see = see
|
self.see = see
|
||||||
self.username = config[CONF_USERNAME]
|
self.username = config[CONF_USERNAME]
|
||||||
self.password = config[CONF_PASSWORD]
|
|
||||||
self.max_gps_accuracy = config[CONF_MAX_GPS_ACCURACY]
|
self.max_gps_accuracy = config[CONF_MAX_GPS_ACCURACY]
|
||||||
|
self.scan_interval = \
|
||||||
|
timedelta(seconds=config.get(CONF_SCAN_INTERVAL, 60))
|
||||||
|
|
||||||
|
credfile = "{}.{}".format(hass.config.path(CREDENTIALS_FILE),
|
||||||
|
slugify(self.username))
|
||||||
try:
|
try:
|
||||||
credfile = "{}.{}".format(hass.config.path(CREDENTIALS_FILE),
|
self.service = Service(credfile, self.username)
|
||||||
slugify(self.username))
|
|
||||||
self.service = Service(self.username, self.password, credfile)
|
|
||||||
self._update_info()
|
self._update_info()
|
||||||
|
|
||||||
track_time_interval(
|
track_time_interval(
|
||||||
hass, self._update_info, MIN_TIME_BETWEEN_SCANS)
|
hass, self._update_info, self.scan_interval)
|
||||||
|
|
||||||
self.success_init = True
|
self.success_init = True
|
||||||
|
|
||||||
except InvalidUser:
|
except InvalidCookies:
|
||||||
_LOGGER.error("You have specified invalid login credentials")
|
_LOGGER.error("You have specified invalid login credentials. "
|
||||||
|
"Please make sure you have saved your credentials"
|
||||||
|
" in the following file: %s", credfile)
|
||||||
self.success_init = False
|
self.success_init = False
|
||||||
|
|
||||||
def _update_info(self, now=None):
|
def _update_info(self, now=None):
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
"name": "Google maps",
|
"name": "Google maps",
|
||||||
"documentation": "https://www.home-assistant.io/components/google_maps",
|
"documentation": "https://www.home-assistant.io/components/google_maps",
|
||||||
"requirements": [
|
"requirements": [
|
||||||
"locationsharinglib==3.0.11"
|
"locationsharinglib==4.0.2"
|
||||||
],
|
],
|
||||||
"dependencies": [],
|
"dependencies": [],
|
||||||
"codeowners": []
|
"codeowners": []
|
||||||
|
|
|
@ -733,7 +733,7 @@ liveboxplaytv==2.0.2
|
||||||
lmnotify==0.0.4
|
lmnotify==0.0.4
|
||||||
|
|
||||||
# homeassistant.components.google_maps
|
# homeassistant.components.google_maps
|
||||||
locationsharinglib==3.0.11
|
locationsharinglib==4.0.2
|
||||||
|
|
||||||
# homeassistant.components.logi_circle
|
# homeassistant.components.logi_circle
|
||||||
logi_circle==0.2.2
|
logi_circle==0.2.2
|
||||||
|
|
Loading…
Reference in New Issue