-
-
Notifications
You must be signed in to change notification settings - Fork 33.9k
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
Conversation
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.
There was a problem hiding this 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!
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
Hey there @thibmaek, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
There was a problem hiding this 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!
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
closing to make some changes as instructed. |
@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: |
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:Type of change
Additional information
Checklist
ruff format homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
.To help with the load of incoming pull requests: