8000 Update to include collection value entities by andreasc1 · Pull Request #146099 · home-assistant/core · GitHub
[go: up one dir, main page]

Skip to content

Update to include collection value entities #146099 8000

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from

Conversation

andreasc1
Copy link
@andreasc1 andreasc1 commented Jun 3, 2025

not experienced, used gemini to help me perform the changes:

Proposed change

This PR introduces new sensor entities for the Home Assistant Discogs integration, allowing users to monitor the estimated value of their Discogs record collection.

Building upon the existing Discogs integration, this enhancement fetches the minimum, median, and maximum estimated values of a user's collection from the Discogs API. These values are exposed as separate Home Assistant sensor entities, providing users with deeper insights into their collection's worth.

The API endpoint used is /users/{username}/collection/value, which returns:

{
  "maximum": "$250.00",
  "median": "$100.25",
  "minimum": "$75.50"
}

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.

To help with the load of incoming pull requests:

not experienced, used gemini to help me perform the changes:
New Constants:
ICON_CASH = "mdi:cash": A new icon for the collection value sensors.
UNIT_CURRENCY = "$": A unit of measurement for currency.
New Sensor Types:
SENSOR_COLLECTION_VALUE_MIN_TYPE
SENSOR_COLLECTION_VALUE_MEDIAN_TYPE
SENSOR_COLLECTION_VALUE_MAX_TYPE
SENSORS Dictionary Update: Added entries for the new sensor types, including their names, icons, and units of measurement.
setup_platform Function:
Added a call to _discogs_client.identity().collection_value to fetch the minimum, median, and maximum values.
Stored these values (collection_value_min, collection_value_median, collection_value_max) in the discogs_data dictionary.
Updated the try-except block to catch general HTTPError and log the error message for better debugging.
DiscogsSensor Class - device_state_attributes:
Modified the device_state_attributes property to handle the new collection value sensors. They will also display attribution and identity.
DiscogsSensor Class - update Method:
Added elif conditions to update the _state for SENSOR_COLLECTION_VALUE_MIN_TYPE, SENSOR_COLLECTION_VALUE_MEDIAN_TYPE, and SENSOR_COLLECTION_VALUE_MAX_TYPE.
Important: The API returns values as strings (e.g., "$250.00"). I've added .replace(UNIT_CURRENCY, '') to remove the currency symbol and float() to convert the string to a floating-point number. This is crucial for Home Assistant to correctly interpret and display these as numeric values, allowing for charting and other numeric operations. The unit_of_measurement property will append the $ symbol in the frontend.
Added a check in get_random_record for an empty collection to prevent errors.
Copy link
@home-assistant home-assistant bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @andreasc1

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@home-assistant
Copy link
home-assistant bot commented Jun 3, 2025

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@home-assistant home-assistant bot marked this pull request as draft June 3, 2025 07:11
@home-assistant
Copy link
home-assistant bot commented Jun 3, 2025

Hey there @thibmaek, mind taking a look at this pull request as it has been labeled with an integration (discogs) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of discogs can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign discogs Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

Copy link
@home-assistant home-assistant bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @andreasc1

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@andreasc1 andreasc1 marked this pull request as ready for review June 3, 2025 07:14
@home-assistant home-assistant bot dismissed stale reviews from themself June 3, 2025 07:14

Stale

Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
@andreasc1 andreasc1 closed this Jun 3, 2025
@andreasc1
Copy link
Author

closing to make some changes as instructed.

@thibmaek
Copy link
Contributor
thibmaek commented Jun 3, 2025

@andreasc1 thanks for trying to implement this functionality. Just FYI when you reopen a new PR: the collection value's valuta is localized depending on the user's geographic location set on the account. I saw you hardcoded it to be USD but that should also change, see screenshot the API response I get from Discogs in EUR:
image

@github-actions github-actions bot locked and limited conversation to collaborators Jun 4, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0