Skip to content

Conversation

@marc7s
Copy link
Contributor

@marc7s marc7s commented May 22, 2025

Breaking change

Proposed change

Adds new sensors for geocaching caches. An upcoming PR will add them to the configuration flow, so you can track caches.

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

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:

@home-assistant
Copy link

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

Code owner commands

Code owners of geocaching 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 geocaching 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
Member

@joostlek joostlek left a comment

Choose a reason for hiding this comment

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

Let's make the PRs even smaller. I think it's also important to keep in mind that we don't necessarily look at the lines of code, but rather how much it's touching, and this is

  1. introducing a base entity
  2. Adding a new platform
  3. Adding more entities
    Which is too much for one PR

@home-assistant
Copy link

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 May 22, 2025 17:11
@marc7s
Copy link
Contributor Author

marc7s commented May 22, 2025

Let's make the PRs even smaller. I think it's also important to keep in mind that we don't necessarily look at the lines of code, but rather how much it's touching, and this is

  1. introducing a base entity
  2. Adding a new platform
  3. Adding more entities
    Which is too much for one PR

@joostlek
I've had this problem before. If I make the PR smaller, I get comments to remove the code as it is "not used in this PR". If I include it, it is "too large".

This PR only introduces a new sensor, a cache sensor. The only thing I could reasonably remove would be the location entity, but then I would get the comment "why is there a base class? it is only derived by a single class". I could remove some of the cache entities, but those are pretty much a few copy pasted lines with slightly different logic (line 82-112 in sensor.py). So what do I do?

@joostlek
Copy link
Member

This PR only introduces a new sensor, a cache sensor

Yes and no, you add more entities, but you are adding the device tracker in a different way.

why is there a base class? it is only derived by a single class

I mean I do see that there is an ongoing effort, so you won't hear this from me.

@marc7s
Copy link
Contributor Author

marc7s commented May 22, 2025

@joostlek So if I remove the device tracker from this PR (and potentially revert the _async_update_data depending on the answer I get on that comment) this PR would be accepted? And I can add the device tracker in a new PR?

@joostlek
Copy link
Member

I think that PR would be a reviewable PR yes.

You can add the others as well, but let's not open more than 3 at the same time (and make sure they don't depend on each other) if you want to work more in parallel

@marc7s marc7s force-pushed the geocaching-caches branch from 9614d86 to 8f9f64c Compare May 22, 2025 21:37
@marc7s
Copy link
Contributor Author

marc7s commented May 22, 2025

@joostlek Reverted _async function, fetched data from the coordinator instead and removed the tracker entity

@marc7s marc7s marked this pull request as ready for review May 22, 2025 21:38
@home-assistant home-assistant bot requested a review from joostlek May 22, 2025 21:38
Copy link
Member

@joostlek joostlek left a comment

Choose a reason for hiding this comment

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

Okay so does the current coordinator already fetch data for the caches?

If so, let's create a base base entity that can be used for the profile and for the caches. This will inherit the coordinatorEntity and declare _attr_has_entity_name.

We can do with a lot less functions, we can inline get_cache_device_info and get_cache_entities

@home-assistant home-assistant bot marked this pull request as draft May 22, 2025 21:41
@marc7s
Copy link
Contributor Author

marc7s commented May 22, 2025

Okay so does the current coordinator already fetch data for the caches?

Yes, when the _async_update_data function is called it fetches the cache data. It is through the call to self.geocaching.update(), which fetches new data from the Geocaching API.

If so, let's create a base base entity that can be used for the profile and for the caches. This will inherit the coordinatorEntity and declare _attr_has_entity_name.

I removed the entity.py file and moved everything to sensor.py to avoid circular dependencies. It does mean that the sensor.py file will get a bit long and cluttered, especially with upcoming PRs but for now it should be fine

We can do with a lot less functions, we can inline get_cache_device_info and get_cache_entities

get_cache_device_info: Sure
get_cache_entities: For now I could yes, since functionality was removed for this PR. I think it might get a bit ugly when the rest is added

@marc7s marc7s force-pushed the geocaching-caches branch from 8f9f64c to 4b19e6a Compare May 22, 2025 22:06
@marc7s marc7s marked this pull request as ready for review May 22, 2025 22:08
@home-assistant home-assistant bot requested a review from joostlek May 22, 2025 22:08
Comment on lines +96 to +100
GeocachingCacheSensorDescription(
key="found_date",
device_class=SensorDeviceClass.DATE,
value_fn=lambda cache: cache.found_date_time,
),
Copy link
Member

Choose a reason for hiding this comment

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

When does this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When the user finds this specific cache

Copy link
Member

Choose a reason for hiding this comment

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

which user? the signed in one or someone else? Like, I am not sure what feature this would add

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The one who authenticates with Geocaching. So me, if I install it. For every cache I add to track, I would see the date when I found that cache. So I can track which caches I have found (easier with the binary sensor) or track history of how often I find caches etc

Comment on lines 101 to 105
GeocachingCacheSensorDescription(
key="favorite_points",
native_unit_of_measurement="points",
value_fn=lambda cache: cache.favorite_points,
),
Copy link
Member

Choose a reason for hiding this comment

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

what's this exactly? Can we add the unit of measurements to strings.json?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The number of times the cache has been favorited. I used the same code for this as the ProfileSensor that already existed before I started by work, favorite_points.

I guess we could, but none of the existing entities does this so I just did the same to keep it cohesive throughout the component.

Copy link
Member

Choose a reason for hiding this comment

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

I don't mind adding it in any case, it's a quick win :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I migrated them all in 2720b28 as I do not like the idea of having different solutions to the same problem in the same component. I want either all to use strings.json, or all to use native_unit_of_measurement.

@home-assistant home-assistant bot marked this pull request as draft May 24, 2025 09:46

# Base class for a cache entity.
# Sets the device, ID and translation settings to correctly group the entity to the correct cache device and give it the correct name.
class GeoEntityBaseCache(GeocachingCacheEntity, SensorEntity):
Copy link
Member

Choose a reason for hiding this comment

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

This one can be merged with GeoEntityCacheSensorEntity now

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Merged how? Moving the entity_description and native_value in here?

I thought you said I should keep this as a good base class, since I will need to derive from this class later when adding the tracker platform. The tracker did not derive from this class previously because it did not use a GeocachingCacheSensorDescription. Are you suggesting I rewrite the tracker to use a sensor description? Previously it derived from TrackerEntity and not SensorEntity as this does, but I am not sure of the inheritence of these classes so TrackerEntity might be a subclass of SensorEntity in which case the double deriving should be fine.

Probably just a misunderstanding, I don't think I understand what you mean with this comment.

Comment on lines 132 to 138
for cache in status.tracked_caches:
entities.extend(
[
GeoEntityCacheSensorEntity(coordinator, cache, description)
for description in CACHE_SENSORS
]
)
Copy link
Member

Choose a reason for hiding this comment

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

you can add the outer for loop to the list comprehension

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, but I thought the readability of nested list comprehensions would be worse. I changed it anyway in eb18e79, but I definately prefer the old way for clearer code to avoid misunderstandings when there are so many maintainers.

@marc7s marc7s requested a review from joostlek May 30, 2025 10:29
@github-actions
Copy link

There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days.
If you are the author of this PR, please leave a comment if you want to keep it open. Also, please rebase your PR onto the latest dev branch to ensure that it's up to date with the latest changes.
Thank you for your contribution!

@github-actions github-actions bot added the stale label Jul 29, 2025
@github-actions github-actions bot closed this Aug 5, 2025
@frenck
Copy link
Member

frenck commented Aug 5, 2025

This was awaiting our review.

@frenck frenck reopened this Aug 5, 2025
@github-actions github-actions bot removed the stale label Aug 5, 2025
Copy link
Contributor

@emontnemery emontnemery left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @marc7s 👍

@emontnemery
Copy link
Contributor

I think it would be great to add tests of the sensors in a follow-up PR 👍

@emontnemery emontnemery marked this pull request as ready for review September 16, 2025 12:13
Copilot AI review requested due to automatic review settings September 16, 2025 12:13
@emontnemery emontnemery merged commit b2c53f2 into home-assistant:dev Sep 16, 2025
60 of 62 checks passed
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds new sensor entities for individual geocaching caches to the geocaching integration. It extends the existing profile-level sensors (finds, hides, etc.) with cache-specific sensors that track information like found date, favorite points, and hidden date for individual caches.

Key changes:

  • Creates cache-specific sensor entities with their own device groupings
  • Adds base entity classes to support both profile and cache entities
  • Updates string translations and icons for the new cache sensors

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
homeassistant/components/geocaching/sensor.py Restructures sensor setup to support both profile and cache sensors, adds new cache sensor classes
homeassistant/components/geocaching/entity.py New file defining base entity classes for profile and cache entities with proper device grouping
homeassistant/components/geocaching/strings.json Adds translations and units for new cache sensors, restructures existing sensor definitions
homeassistant/components/geocaching/icons.json Adds icon definitions for new cache sensor types
Comments suppressed due to low confidence (5)

homeassistant/components/geocaching/sensor.py:1

  • The native_unit_of_measurement fields are being removed from the entity descriptions but the corresponding units in strings.json use different strings ('caches' vs 'cache'). This inconsistency could cause confusion - ensure the unit naming is standardized between the code and translation files.
"""Platform for sensor integration."""

homeassistant/components/geocaching/sensor.py:1

  • The native_unit_of_measurement fields are being removed from the entity descriptions but the corresponding units in strings.json use different strings ('caches' vs 'cache'). This inconsistency could cause confusion - ensure the unit naming is standardized between the code and translation files.
"""Platform for sensor integration."""

homeassistant/components/geocaching/sensor.py:1

  • The native_unit_of_measurement fields are being removed from the entity descriptions but the corresponding units in strings.json use different strings ('caches' vs 'cache'). This inconsistency could cause confusion - ensure the unit naming is standardized between the code and translation files.
"""Platform for sensor integration."""

homeassistant/components/geocaching/sensor.py:1

  • The native_unit_of_measurement fields are being removed from the entity descriptions but the corresponding units in strings.json use different strings ('caches' vs 'cache'). This inconsistency could cause confusion - ensure the unit naming is standardized between the code and translation files.
"""Platform for sensor integration."""

homeassistant/components/geocaching/sensor.py:1

  • The native_unit_of_measurement fields are being removed from the entity descriptions but the corresponding units in strings.json use different strings ('caches' vs 'cache'). This inconsistency could cause confusion - ensure the unit naming is standardized between the code and translation files.
"""Platform for sensor integration."""

self._attr_translation_key = f"cache_{key}"


class GeoEntityCacheSensorEntity(GeoEntityBaseCache, SensorEntity):
Copy link

Copilot AI Sep 16, 2025

Choose a reason for hiding this comment

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

This class inherits from both GeoEntityBaseCache (which already inherits from SensorEntity) and SensorEntity directly, creating redundant inheritance. Remove the direct SensorEntity inheritance since it's already provided by the base class.

Suggested change
class GeoEntityCacheSensorEntity(GeoEntityBaseCache, SensorEntity):
class GeoEntityCacheSensorEntity(GeoEntityBaseCache):

Copilot uses AI. Check for mistakes.
@github-actions github-actions bot locked and limited conversation to collaborators Sep 17, 2025
@marc7s marc7s deleted the geocaching-caches branch September 18, 2025 14:31
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.

4 participants