def test_GoogleLocator_WithAPIKey(): if api_key: locator = GoogleGeocoder(api_key=api_key) l = locator['Eiffel Tower'] assert l is not None else: raise AssertionError('api_key not found')
def setup(hass, config): """ Tracks the state of the sun. """ if None in (hass.config.latitude, hass.config.longitude): _LOGGER.error("Latitude or longitude not set in Home Assistant config") return False latitude = util.convert(hass.config.latitude, float) longitude = util.convert(hass.config.longitude, float) errors = [] if latitude is None: errors.append('Latitude needs to be a decimal value') elif -90 > latitude < 90: errors.append('Latitude needs to be -90 .. 90') if longitude is None: errors.append('Longitude needs to be a decimal value') elif -180 > longitude < 180: errors.append('Longitude needs to be -180 .. 180') if errors: _LOGGER.error('Invalid configuration received: %s', ", ".join(errors)) return False platform_config = config.get(DOMAIN, {}) elevation = platform_config.get(CONF_ELEVATION) from astral import Location, GoogleGeocoder location = Location( ('', '', latitude, longitude, hass.config.time_zone, elevation or 0)) if elevation is None: google = GoogleGeocoder() try: google._get_elevation(location) # pylint: disable=protected-access _LOGGER.info('Retrieved elevation from Google: %s', location.elevation) except urllib.error.URLError: # If no internet connection available etc. pass sun = Sun(hass, location) sun.point_in_time_listener(dt_util.utcnow()) return True
def setup(hass, config): """ Tracks the state of the sun. """ if None in (hass.config.latitude, hass.config.longitude): _LOGGER.error("Latitude or longitude not set in Home Assistant config") return False latitude = util.convert(hass.config.latitude, float) longitude = util.convert(hass.config.longitude, float) errors = [] if latitude is None: errors.append('Latitude needs to be a decimal value') elif -90 > latitude < 90: errors.append('Latitude needs to be -90 .. 90') if longitude is None: errors.append('Longitude needs to be a decimal value') elif -180 > longitude < 180: errors.append('Longitude needs to be -180 .. 180') if errors: _LOGGER.error('Invalid configuration received: %s', ", ".join(errors)) return False platform_config = config.get(DOMAIN, {}) elevation = platform_config.get(CONF_ELEVATION) from astral import Location, GoogleGeocoder location = Location(('', '', latitude, longitude, hass.config.time_zone, elevation or 0)) if elevation is None: google = GoogleGeocoder() try: google._get_elevation(location) # pylint: disable=protected-access _LOGGER.info( 'Retrieved elevation from Google: %s', location.elevation) except urllib.error.URLError: # If no internet connection available etc. pass sun = Sun(hass, location) sun.point_in_time_listener(dt_util.utcnow()) return True
def test_GoogleLocator_WithAPIKey(): # 1st try to use the API_KEY environment variable that we encrypted # in our .travis.yml api_key = os.environ.get("API_KEY", None) if not api_key: try: api_key = read_contents(os.path.dirname(__file__), '.api_key').strip() except IOError as exc: raise ValueError("Google now requires an API key to be provided") locator = GoogleGeocoder(api_key=api_key) l = locator['Eiffel Tower'] assert l is not None
def __getitem__(self, key): return GoogleGeocoder.__getitem__(self, key)
def __init__(self): google_maps_api_key = Firestore().google_maps_api_key() GoogleGeocoder.__init__(self, api_key=google_maps_api_key, cache=False)
def test_GoogleLocator(): locator = GoogleGeocoder() l = locator['Eiffel Tower'] assert l is not None
from . import config class Weekday(IntEnum): MONDAY = 0 TUESDAY = 1 WEDNESDAY = 2 THURSDAY = 3 FRIDAY = 4 SATURDAY = 5 SUNDAY = 6 ASTRAL = Astral() ASTRAL.geocoder = GoogleGeocoder(cache=True) DAY_MOMENTS = { 'blue_hour', 'blue_hour_middle', 'blue_hour_end', 'dawn', 'dusk', 'golden_hour', 'golden_hour_middle', 'golden_hour_end', 'solar_noon', 'sunrise', 'sunset', 'twilight', 'twilight_middle', 'twilight_end',
def test_GoogleLocator_WithAPIKey(): locator = GoogleGeocoder(api_key=api_key) l = locator['Eiffel Tower'] assert l is not None