Skip to content
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

Add concentration level sensor to Aranet #137291

Open
wants to merge 14 commits into
base: dev
Choose a base branch
from

Conversation

parkerbxyz
Copy link

@parkerbxyz parkerbxyz commented Feb 4, 2025

Proposed change

Adds a threshold level sensor so you can see the threshold levels from the Aranet4 and AranetRn+ in Home Assistant.

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:
  • Link to developer documentation pull request:
  • Link to frontend 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:

@home-assistant
Copy link

home-assistant bot commented Feb 4, 2025

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

Code owner commands

Code owners of aranet 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 aranet 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.

@parkerbxyz parkerbxyz marked this pull request as ready for review February 6, 2025 05:23
@parkerbxyz parkerbxyz requested a review from thecode as a code owner February 6, 2025 05:23
status_sensor_attrs = status_sensor.attributes
assert status_sensor.state == "GREEN"
assert status_sensor_attrs[ATTR_FRIENDLY_NAME] == "Aranet4 12345 Threshold Level"
assert set(status_sensor_attrs[ATTR_OPTIONS]) == {"ERROR", "GREEN", "YELLOW", "RED"}
Copy link
Author

@parkerbxyz parkerbxyz Feb 6, 2025

Choose a reason for hiding this comment

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

I'd love to map these to more useful values. For example, the CO₂ could have the following mappings:

  • GREEN → Good
  • YELLOW → Average
  • RED → Unhealthy

For the Radon sensor:

  • GREEN → Normal
  • YELLOW → Elevated
  • RED → Unhealthy

I'm just not sure if that would be considered in scope for this integration.

Copy link
Contributor

Choose a reason for hiding this comment

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

From end-user viewpoint, it would make more sense to map them to more understandable names

Copy link
Author

Choose a reason for hiding this comment

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

In that case, I'll work on implementing this. Thanks for the quick feedback!

Copy link
Contributor

Choose a reason for hiding this comment

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

OTOH, isn't the user expecting to see "Red/Yellow/Green", based on the official app and device screen?

Copy link
Author

Choose a reason for hiding this comment

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

They are just colors in the app on the device. If you look in the device settings or the manuals/documentation, it explains what those values translate to, which is where I got these values from. I'm still using Aranet's terminology.

Copy link
Contributor

Choose a reason for hiding this comment

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

Personally, I would view the descriptive (Good/Average/Unhealthy) terms as more useful on a dashboard, so that would be my preference. I understand that they are not necessarily as obvious when looking at the device, though, so if there's a consensus in another direction that's fine too.

My only concern would be that they would possibly require some care when handling the translation strings (especially because this meaning of "average" isn't necessarily "the mean of some numbers"), but I'd find it more useful to see "Unhealthy" than "Red" on a HA card.

Copy link
Author

Choose a reason for hiding this comment

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

Personally, I would view the descriptive (Good/Average/Unhealthy) terms as more useful on a dashboard, so that would be my preference.

Certainly, a dashboard is where I would want to use those values, too. That was my motivation. However, I'm also open to sticking to the colors.

My only concern would be that they would possibly require some care when handling the translation strings (especially because this meaning of "average" isn't necessarily "the mean of some numbers

This is a good call-out. Perhaps if we do use these more human-friendly values, we should stick with one set (i.e., normal, elevated, and unhealthy) rather than having different values per device type.

@parkerbxyz parkerbxyz marked this pull request as draft February 6, 2025 06:35
@parkerbxyz parkerbxyz marked this pull request as ready for review February 6, 2025 08:46
@parkerbxyz parkerbxyz changed the title Add threshold level sensor to Aranet Add concentration status sensor to Aranet Feb 6, 2025
@parkerbxyz parkerbxyz changed the title Add concentration status sensor to Aranet Add concentration level sensor to Aranet Feb 6, 2025
@@ -161,7 +166,11 @@ def sensor_update_to_bluetooth_data_update(
val = getattr(adv.readings, key)
if val == -1:
continue
val *= desc.scale
val = (
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of this, can we set the translation_key add add translations for the states?
Also, isn't the user expecting to see "Red/Yellow/Green", based on the official app and device screen?

Copy link
Member

Choose a reason for hiding this comment

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

I agree, I think we should represent it same as the app does, also for the translations (was actually waiting to have time to search for example for the translations later, thanks @abmantis)

Copy link
Author

Choose a reason for hiding this comment

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

Sure, I'll add translations for the states instead.

Also, isn't the user expecting to see "Red/Yellow/Green", based on the official app and device screen?

I'm not sure if this would necessarily be the expectation. See #137291 (comment).

Copy link
Author

@parkerbxyz parkerbxyz Feb 7, 2025

Choose a reason for hiding this comment

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

I'm not sure if I did the translations correctly, and I haven't figured out how to test the translations programmatically. Could someone take a look at the latest changes and let me know if you have any further suggestions?

@home-assistant home-assistant bot marked this pull request as draft February 6, 2025 22:03
@home-assistant
Copy link

home-assistant bot commented Feb 6, 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.

@parkerbxyz parkerbxyz marked this pull request as ready for review February 7, 2025 07:34
@home-assistant home-assistant bot requested a review from abmantis February 7, 2025 07:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants