Skip to content

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Jul 6, 2025

The download counter was showing incorrect values for repositories with multiple release assets. The issue occurred because HACS always used the download count from the first asset in the release instead of the asset specified by the filename field in the repository manifest (hacs.yaml).

Problem

When a repository has multiple release assets, the download counter would display the download count from the first asset rather than the correct asset. For example, the mbapi2020 component was showing ~190 downloads (from the first asset) instead of ~4000 downloads (from the correct mbapi2020.zip asset).

Root Cause

In custom_components/hacs/repositories/base.py, the code used next(iter(assets)).download_count which always retrieves the first asset from the assets list, regardless of which asset is actually being used for the repository.

Solution

Modified the download counting logic to:

  1. Search for an asset that matches self.data.file_name (the filename specified in the repository manifest)
  2. Use that asset's download count if found
  3. Fall back to the first asset if no match is found or file_name is None (preserving existing behavior)
# Find the correct asset based on file_name, fallback to first asset target_asset = None if self.data.file_name: for asset in assets: if asset.name == self.data.file_name: target_asset = asset break # Use the target asset if found, otherwise use the first asset if target_asset: downloads = target_asset.download_count else: downloads = next(iter(assets)).download_count

Changes Made

  • custom_components/hacs/repositories/base.py: Updated download counting logic in the common_update_data method
  • tests/repositories/test_download_counter.py: Added comprehensive test coverage for all scenarios

Validation

The fix has been validated to:

  • ✅ Correctly identify and use the specified asset's download count
  • ✅ Gracefully fall back to the first asset when no filename is specified
  • ✅ Handle edge cases where the specified filename doesn't match any asset
  • ✅ Maintain backward compatibility with existing repositories

Fixes #4438.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

…ple release assets Co-authored-by: ludeeus <15093472+ludeeus@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Download counter shows wrong value Fix download counter to use correct asset for repositories with multiple release assets Jul 6, 2025
@Copilot Copilot AI requested a review from ludeeus July 6, 2025 07:36
Copilot finished work on behalf of ludeeus July 6, 2025 07:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants