Skip to content

Commit

Permalink
Merge pull request #110 from craibo/2023.5.1
Browse files Browse the repository at this point in the history
2023.5.1
  • Loading branch information
craibo authored May 10, 2023
2 parents df8f2e1 + bf47d4f commit 533232d
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ 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
### 3. Geocode.xyz API Key

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.

Expand Down
6 changes: 6 additions & 0 deletions custom_components/ha_strava/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
CONF_DISTANCE_UNIT_OVERRIDE_IMPERIAL = "imperial"
CONF_GEOCODE_XYZ_API_KEY = "geocode_xyz_api_key"

STRAVA_ACTIVITY_BASE_URL = "https://www.strava.com/activities/"
STRAVA_ACTHLETE_BASE_URL = ""

# Event Specs
CONF_STRAVA_DATA_UPDATE_EVENT = "strava_data_update"
CONF_STRAVA_CONFIG_UPDATE_EVENT = "strava_config_update"
Expand Down Expand Up @@ -142,6 +145,9 @@
CONF_ATTR_LOCATION = "location"
CONF_ATTR_TITLE = "title"
CONF_ATTR_ACTIVITY_ID = "activity_id"
CONF_ATTR_ACTIVITY_URL = "activity_url"
CONF_ATTR_ATHLETE_ID = "athlete_id"
CONF_ATTR_ATHLETE_URL = "athlete_url"

UNIT_BEATS_PER_MINUTE = "bpm"
UNIT_PACE_MINUTES_PER_KILOMETER = "min/km"
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.21"
"version": "3.2.22"
}
18 changes: 15 additions & 3 deletions custom_components/ha_strava/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
CONF_ACTIVITY_TYPE_WALK,
CONF_ACTIVITY_TYPE_WORKOUT,
CONF_ATTR_ACTIVITY_ID,
CONF_ATTR_ACTIVITY_URL,
CONF_ATTR_ATHLETE_ID,
CONF_ATTR_ATHLETE_URL,
CONF_ATTR_LOCATION,
CONF_ATTR_SPORT_TYPE,
CONF_ATTR_START_LATLONG,
Expand Down Expand Up @@ -72,6 +75,8 @@
EVENT_ACTIVITIES_UPDATE,
EVENT_SUMMARY_STATS_UPDATE,
MAX_NB_ACTIVITIES,
STRAVA_ACTIVITY_BASE_URL,
STRAVA_ACTHLETE_BASE_URL,
UNIT_BEATS_PER_MINUTE,
UNIT_KILO_CALORIES,
UNIT_PACE_MINUTES_PER_KILOMETER,
Expand Down Expand Up @@ -172,7 +177,7 @@ def device_info(self):
"name": f"Strava Summary",
"manufacturer": "Strava",
"model": "Activity Summary",
"configuration_url": f"https://www.strava.com/athletes/{athlete_id}",
"configuration_url": f"{STRAVA_ACTHLETE_BASE_URL}{athlete_id}",
}

@property
Expand Down Expand Up @@ -299,6 +304,11 @@ def capability_attributes(self): # pylint: disable=too-many-return-statements
if not self._data:
return attr

athlete_id = str(self._data[CONF_SENSOR_ID])
if athlete_id:
attr[CONF_ATTR_ATHLETE_ID] = f"{athlete_id}"
attr[CONF_ATTR_ATHLETE_URL] = f"{STRAVA_ACTHLETE_BASE_URL}{athlete_id}"

if self._metric == CONF_SENSOR_MOVING_TIME:
attr[CONF_DEVICE_CLASS] = DEVICE_CLASS_DURATION
return attr
Expand Down Expand Up @@ -368,7 +378,7 @@ def device_info(self):
"name": f"Strava Activity {self._activity_index}",
"manufacturer": "Strava",
"model": "Activity",
"configuration_url": f"https://www.strava.com/activities/{activity_id}",
"configuration_url": f"{STRAVA_ACTIVITY_BASE_URL}{activity_id}",
}

@property
Expand Down Expand Up @@ -688,11 +698,13 @@ def capability_attributes(self): # pylint: disable=too-many-return-statements
return attr

if self._sensor_index == 0:
activity_id = str(self._data[CONF_SENSOR_ID])
attr[CONF_DEVICE_CLASS] = DEVICE_CLASS_DATE
attr[CONF_ATTR_ACTIVITY_ID] = activity_id
attr[CONF_ATTR_SPORT_TYPE] = self._data[CONF_ATTR_SPORT_TYPE]
attr[CONF_ATTR_LOCATION] = self._data[CONF_SENSOR_CITY]
attr[CONF_ATTR_TITLE] = self._data[CONF_SENSOR_TITLE]
attr[CONF_ATTR_ACTIVITY_ID] = str(self._data[CONF_SENSOR_ID])
attr[CONF_ATTR_ACTIVITY_URL] = f"{STRAVA_ACTIVITY_BASE_URL}{activity_id}"
if self._data[CONF_ATTR_START_LATLONG]:
attr[CONF_LATITUDE] = float(
self._data[CONF_ATTR_START_LATLONG][0]
Expand Down
2 changes: 1 addition & 1 deletion info.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ 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
### 3. Geocode.xyz API Key

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.

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.21"
"version": "3.2.22"
}

0 comments on commit 533232d

Please sign in to comment.