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

Introduce unit enums for sound pressure #83450

Merged
merged 3 commits into from Dec 8, 2022

Conversation

epenet
Copy link
Contributor

@epenet epenet commented Dec 7, 2022

Breaking change

FOR DEVELOPPERS ONLY: as of Home Assistant Core 2023.1, the following unit constants are deprecated and replaced
by a corresponding enum:

  • UnitOfSoundPressure enumerator replaces SOUND_PRESSURE_** constants

Proposed change

Introduce unit enums for sound pressure

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
  • The code has been formatted using Black (black --fast 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.
  • Untested files have been added to .coveragerc.

To help with the load of incoming pull requests:

@home-assistant home-assistant bot added cla-signed core deprecation Indicates a breaking change to happen in the future new-feature small-pr PRs with less than 30 lines. labels Dec 7, 2022
@epenet epenet requested a review from a team as a code owner December 7, 2022 14:10
"""Sound pressure units."""

DECIBEL = "dB"
WEIGHTED_DECIBEL_A = "dB(A)"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason for hiding this comment

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

Nothing wrong with this, but just adding some extra info.

dBA is also acceptable (also noted in the Wikipedia page). Common usage (from what I've seen) is dBA over dB(A). Definitely not dBa.

For a really comprehensive list of dB variants see https://en.wikipedia.org/wiki/Decibel.

A second thing (which probably displays my lack of knowledge around unit management in HA) is this:
Can units have properties, e.g. so that the unit is dB, but there's an attribute/property to say it uses A-weighted values?

dBA, dBB, and dBC
These symbols are often used to denote the use of different weighting filters, used to approximate the human ear's response to sound, although the measurement is still in dB (SPL). These measurements usually refer to noise and its effects on humans and other animals, and they are widely used in industry while discussing noise control issues, regulations and environmental standards. Other variations that may be seen are dBA or dB(A). According to standards from the International Electro-technical Committee (IEC 61672-2013)[52] and the American National Standards Institute, ANSI S1.4,[53] the preferred usage is to write LA = x dB. Nevertheless, the units dBA and dB(A) are still commonly used as a shorthand for A‑weighted measurements. Compare dBc, used in telecommunications.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As you said, the current variant dBa isn't really valid.
I prefer dB(A) over dBA because I think it makes it clearer it's added information.

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.

Thanks, @epenet 👍

@frenck
Copy link
Member

frenck commented Dec 8, 2022

image

image

I would say dBA is significantly more common.

Copy link
Member

@frenck frenck left a comment

Choose a reason for hiding this comment

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

Thanks, @epenet 👍

@epenet epenet merged commit 96c4423 into home-assistant:dev Dec 8, 2022
@epenet epenet deleted the sound-pressure branch December 8, 2022 19:06
@github-actions github-actions bot locked and limited conversation to collaborators Dec 9, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla-signed core deprecation Indicates a breaking change to happen in the future new-feature small-pr PRs with less than 30 lines.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants