Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberjunky committed Feb 8, 2025
1 parent c941044 commit 83e8e52
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 14 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ action:
mode: single
```

### Examples on how to test services from HA GUI
### Examples on how to test actions from HA GUI

#### Add Body Composition

Expand All @@ -189,10 +189,10 @@ data:
weight: 87
bmi: 25.5
bone_mass: 4.8
...
```
See the action template for other available values to add

NOTE: You need to enable Weight entity
NOTE: You need to enable the Weight entity

#### Set Active Gear

Expand Down
25 changes: 18 additions & 7 deletions custom_components/garmin_connect/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
import requests

from .const import (
DATA_COORDINATOR,
Expand Down Expand Up @@ -196,19 +197,29 @@ async def _async_update_data(self) -> dict:
)
_LOGGER.debug("Gear data fetched: %s", gear)

gear_defaults = await self.hass.async_add_executor_job(
self.api.get_gear_defaults, summary[Gear.USERPROFILE_ID]
)
_LOGGER.debug("Gear defaults data fetched: %s", gear_defaults)
except (KeyError, TypeError, ValueError, ConnectionError) as err:
_LOGGER.debug("Error while fetching Gear data: %s", err)

# Gear stats data
try:
tasks: list[Awaitable] = [
self.hass.async_add_executor_job(self.api.get_gear_stats, gear_item[Gear.UUID])
for gear_item in gear
]
gear_stats = await asyncio.gather(*tasks)
_LOGGER.debug("Gear stats data fetched: %s", gear_stats)

gear_defaults = await self.hass.async_add_executor_job(
self.api.get_gear_defaults, summary[Gear.USERPROFILE_ID]
)
_LOGGER.debug("Gear defaults data fetched: %s", gear_defaults)
except (KeyError, TypeError, ValueError, ConnectionError) as err:
_LOGGER.debug("Gear data is not available: %s", err)
except (
KeyError,
TypeError,
ValueError,
ConnectionError,
requests.exceptions.HTTPError,
) as err:
_LOGGER.debug("Error while fetching Gear stats data: %s", err)

# Sleep score data
try:
Expand Down
2 changes: 1 addition & 1 deletion custom_components/garmin_connect/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/cyberjunky/home-assistant-garmin_connect/issues",
"requirements": ["garminconnect>=0.2.24"],
"version": "0.2.29"
"version": "0.2.30"
}
7 changes: 5 additions & 2 deletions custom_components/garmin_connect/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,16 @@ def extra_state_attributes(self):
"last_synced": self.coordinator.data["lastSyncTimestampGMT"],
}

# Only add the last 5 activities for performance reasons
if self._type == "lastActivities":
attributes["last_activities"] = self.coordinator.data[self._type]
activities = self.coordinator.data.get(self._type, [])
sorted_activities = sorted(activities, key=lambda x: x["activityId"])
attributes["last_activities"] = sorted_activities[-5:]

if self._type == "lastActivity":
attributes = {**attributes, **self.coordinator.data[self._type]}

# Only show the last 10 badges for performance reasons
# Only add the last 10 badges for performance reasons
if self._type == "badges":
badges = self.coordinator.data.get(self._type, [])
sorted_badges = sorted(badges, key=lambda x: x["badgeEarnedDate"])
Expand Down
1 change: 0 additions & 1 deletion requirements_core_min.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
# homeassistant==2024.4.1
homeassistant==2025.1.4

0 comments on commit 83e8e52

Please sign in to comment.