diff --git a/homeassistant/components/google_maps/device_tracker.py b/homeassistant/components/google_maps/device_tracker.py index 5788392190a..4791cb25b47 100644 --- a/homeassistant/components/google_maps/device_tracker.py +++ b/homeassistant/components/google_maps/device_tracker.py @@ -2,17 +2,19 @@ from datetime import timedelta import logging +from locationsharinglib import Service +from locationsharinglib.locationsharinglibexceptions import InvalidCookies import voluptuous as vol from homeassistant.components.device_tracker import ( PLATFORM_SCHEMA, SOURCE_TYPE_GPS) from homeassistant.const import ( - ATTR_ID, CONF_PASSWORD, CONF_USERNAME, ATTR_BATTERY_CHARGING, - ATTR_BATTERY_LEVEL) + ATTR_BATTERY_CHARGING, ATTR_BATTERY_LEVEL, ATTR_ID, CONF_SCAN_INTERVAL, + CONF_USERNAME) import homeassistant.helpers.config_validation as cv from homeassistant.helpers.event import track_time_interval 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__) @@ -25,10 +27,7 @@ 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_PASSWORD): cv.string, vol.Required(CONF_USERNAME): cv.string, 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: """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] + self.scan_interval = \ + timedelta(seconds=config.get(CONF_SCAN_INTERVAL, 60)) + credfile = "{}.{}".format(hass.config.path(CREDENTIALS_FILE), + slugify(self.username)) try: - credfile = "{}.{}".format(hass.config.path(CREDENTIALS_FILE), - slugify(self.username)) - self.service = Service(self.username, self.password, credfile) + self.service = Service(credfile, self.username) self._update_info() track_time_interval( - hass, self._update_info, MIN_TIME_BETWEEN_SCANS) + hass, self._update_info, self.scan_interval) self.success_init = True - except InvalidUser: - _LOGGER.error("You have specified invalid login credentials") + except InvalidCookies: + _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 def _update_info(self, now=None): diff --git a/homeassistant/components/google_maps/manifest.json b/homeassistant/components/google_maps/manifest.json index 7d6aeeef041..5f31f533a38 100644 --- a/homeassistant/components/google_maps/manifest.json +++ b/homeassistant/components/google_maps/manifest.json @@ -3,7 +3,7 @@ "name": "Google maps", "documentation": "https://www.home-assistant.io/components/google_maps", "requirements": [ - "locationsharinglib==3.0.11" + "locationsharinglib==4.0.2" ], "dependencies": [], "codeowners": [] diff --git a/requirements_all.txt b/requirements_all.txt index 2546dca6c5c..7f274a5c19a 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -733,7 +733,7 @@ liveboxplaytv==2.0.2 lmnotify==0.0.4 # homeassistant.components.google_maps -locationsharinglib==3.0.11 +locationsharinglib==4.0.2 # homeassistant.components.logi_circle logi_circle==0.2.2