Skip to content

Allow customizing unit for temperature and pressure sensors#64366

Merged
emontnemery merged 15 commits intodevfrom
sensor_customize_unit
Mar 30, 2022
Merged

Allow customizing unit for temperature and pressure sensors#64366
emontnemery merged 15 commits intodevfrom
sensor_customize_unit

Conversation

@emontnemery
Copy link
Copy Markdown
Contributor

@emontnemery emontnemery commented Jan 18, 2022

Proposed change

Allow customizing unit for temperature and pressure sensors

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)
  • 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.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

To help with the load of incoming pull requests:

@probot-home-assistant
Copy link
Copy Markdown

Hey there @Danielhiversen, @felipediel, @L-I-Am, mind taking a look at this pull request as it has been labeled with an integration (broadlink) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)

@emontnemery emontnemery marked this pull request as draft January 18, 2022 14:38
Comment on lines +559 to +525
and self.device_class in UNIT_CONVERSIONS
and (device_class := self.device_class) in UNIT_CONVERSIONS
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Isn't this double?

Suggested change
and self.device_class in UNIT_CONVERSIONS
and (device_class := self.device_class) in UNIT_CONVERSIONS
and (device_class := self.device_class) in UNIT_CONVERSIONS

Copy link
Copy Markdown
Contributor Author

@emontnemery emontnemery Jan 24, 2022

Choose a reason for hiding this comment

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

Fixed in 4a32a28


native_unit_of_measurement = self.native_unit_of_measurement

if self._sensor_option_unit_of_measurement:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Shouldn't this be the first check ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 4a32a28

@emontnemery emontnemery force-pushed the sensor_customize_unit branch from d66f1b2 to 46ca5e9 Compare March 29, 2022 13:05
@emontnemery emontnemery marked this pull request as ready for review March 29, 2022 13:59
@emontnemery emontnemery changed the title Draft: Allow customizing unit for temperature and pressure sensors Allow customizing unit for temperature and pressure sensors Mar 29, 2022

if msg["entity_id"] not in registry.entities:
entity_id = msg["entity_id"]
if entity_id not in registry.entities:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Shouldn't you just store the entry here in a var so you don't need to fetch it inside the disabled_by if ?

value = round(value_f_new) if prec == 0 else round(value_f_new, prec)

units = self.hass.config.units
if (
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This can be an elif?


msg = await client.receive_json()

assert msg["result"] == {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is beard_second not an error ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh I guess that entity registry doesn't know about valid sensor options.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yeah, that's right.

emontnemery and others added 2 commits March 30, 2022 14:11
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
@emontnemery
Copy link
Copy Markdown
Contributor Author

@rianadon I think this approach would be useful to allow customizing weather entity units. You can contact me on Discord, emontnemery#6618, if you want to discuss it.

@emontnemery emontnemery merged commit 91f6e58 into dev Mar 30, 2022
@emontnemery emontnemery deleted the sensor_customize_unit branch March 30, 2022 13:43
@github-actions github-actions bot locked and limited conversation to collaborators Mar 31, 2022
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.

5 participants