Skip to content

Commit

Permalink
Merge pull request #102 from craibo/2023.5.0
Browse files Browse the repository at this point in the history
2023.5.0
  • Loading branch information
craibo authored May 7, 2023
2 parents 7915051 + 8ee6a01 commit 6f18716
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 9 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ Three configurations for the **_distance unit system_** are available.

This setting is selectable on configuration of the Strava integration and from the Strava Home Assistant Integration under `Configuration` > `Integrations`, click on `CONFIGURE`.

### 3. Geocode.xyz API kKey

If your activity titles are constantly showing the area as **Unknown Area**, this is likely a result of the geocode.xyz api throttling. You are able to register for a free geocode.xyz account which will provide you with an API key. This key will reduce the throttling applied your geocoding queries.

1. Go to https://geocode.xyz/new_account to register your account.
2. Copy the provided API key
3. Paste the API Key in the configuration of the Strava Home Assistant Integration found here: `Configuration` > `Integrations`, click on `CONFIGURE`.

**_NOTES_**

1. Changing the unit system setting will require a restart of Home Assistant to be fully applied.
Expand Down
11 changes: 4 additions & 7 deletions custom_components/ha_strava/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import asyncio
import json
import logging
import time
from datetime import datetime as dt
from http import HTTPStatus
from typing import Callable, Tuple
Expand Down Expand Up @@ -183,11 +182,7 @@ async def _geocode_activity(self, activity: dict, auth: str) -> str:
# Allow 3 attempts to resolve the geocode due to throttling
geo_location = await self._make_geocode_request(start_latlng=start_latlng, auth=auth)
city = geo_location.get("city", None)
if not city or city == GEOCODE_XYZ_THROTTLED:
retries += 1
time.sleep(1)
else:
retries = 3
retries += 1 if not city or city == GEOCODE_XYZ_THROTTLED else 3

city = geo_location.get("city", None)
if city:
Expand All @@ -196,9 +191,11 @@ async def _geocode_activity(self, activity: dict, auth: str) -> str:
return UNKNOWN_AREA

async def _make_geocode_request(self, start_latlng: dict, auth: str) -> dict:
url = "".join([f"https://geocode.xyz/{start_latlng[0]},{start_latlng[1]}?geoit=json", f"&auth={auth}" if auth else f""]), # noqa: E501
_LOGGER.debug(f"Geocode.xyz Url: {url}")
geo_location_response = await self.oauth_websession.async_request(
method="GET",
url="".join([f"https://geocode.xyz/{start_latlng[0]},{start_latlng[1]}?geoit=json", f"" if not auth else f"&auth={auth}"]), # noqa: E501
url=url
)
return await geo_location_response.json()

Expand Down
2 changes: 1 addition & 1 deletion custom_components/ha_strava/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"iot_class": "cloud_polling",
"name": "HA Strava 2.0",
"requirements": ["aiohttp>=3.6.1", "voluptuous>=0.11.7"],
"version": "3.2.16"
"version": "3.2.17"
}
8 changes: 8 additions & 0 deletions info.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ Three configurations for the **_distance unit system_** are available.

This setting is selectable on configuration of the Strava integration and from the Strava Home Assistant Integration under `Configuration` > `Integrations`, click on `CONFIGURE`.

### 3. Geocode.xyz API kKey

If your activity titles are constantly showing the area as **Unknown Area**, this is likely a result of the geocode.xyz api throttling. You are able to register for a free geocode.xyz account which will provide you with an API key. This key will reduce the throttling applied your geocoding queries.

1. Go to https://geocode.xyz/new_account to register your account.
2. Copy the provided API key
3. Paste the API Key in the configuration of the Strava Home Assistant Integration found here: `Configuration` > `Integrations`, click on `CONFIGURE`.

**_NOTES_**

1. Changing the unit system setting will require a restart of Home Assistant to be fully applied.
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"iot_class": "cloud_polling",
"name": "HA Strava 2.0",
"requirements": ["aiohttp>=3.6.1", "voluptuous>=0.11.7"],
"version": "3.2.16"
"version": "3.2.17"
}

0 comments on commit 6f18716

Please sign in to comment.