1
0
mirror of https://github.com/home-assistant/core.git synced 2025-08-21 19:30:02 +00:00
Commit Graph

95 Commits

Author SHA1 Message Date
Richard Kroegel
865190f0b0 Get suggested_unit_of_measurement via unit converter's UNIT_CLASS ()
Co-authored-by: Richard <rikroe@users.noreply.github.com>
Co-authored-by: Erik Montnemery <erik@montnemery.com>
2024-07-10 17:45:07 +02:00
Marc Mueller
f11b316dac Import Generator from collections.abc (4) () 2024-07-01 11:54:42 +02:00
Joost Lekkerkerker
0fdf037ba0 Fix ruff type comparison E721 ()
Fix E721
2024-06-28 11:56:49 +02:00
G Johansson
b59e7ede9a Raise on incorrect suggested unit for sensor () 2024-06-22 22:05:45 +02:00
epenet
2e3c3789d3 Use relative imports in tests [s-z] () 2024-06-10 13:33:15 +02:00
Marc Mueller
837ee7c4fb Import Generator from typing_extensions (4) () 2024-06-06 17:41:37 +02:00
J. Nick Koston
ed0568c655 Ensure config entries are not unloaded while their platforms are setting up ()
* Report non-awaited/non-locked config entry platform forwards

Its currently possible for config entries to be reloaded while their platforms
are being forwarded if platform forwards are not awaited or done after the
config entry is setup since the lock will not be held in this case.

In https://developers.home-assistant.io/blog/2022/07/08/config_entry_forwards
we advised to await platform forwards to ensure this does not happen, however
for sleeping devices and late discovered devices, platform forwards may happen
later.

If config platform forwards are happening during setup, they should be awaited

If config entry platform forwards are not happening during setup, instead
async_late_forward_entry_setups should be used which will hold the lock to
prevent the config entry from being unloaded while its platforms are being
setup

* Report non-awaited/non-locked config entry platform forwards

Its currently possible for config entries to be reloaded while their platforms
are being forwarded if platform forwards are not awaited or done after the
config entry is setup since the lock will not be held in this case.

In https://developers.home-assistant.io/blog/2022/07/08/config_entry_forwards
we advised to await platform forwards to ensure this does not happen, however
for sleeping devices and late discovered devices, platform forwards may happen
later.

If config platform forwards are happening during setup, they should be awaited

If config entry platform forwards are not happening during setup, instead
async_late_forward_entry_setups should be used which will hold the lock to
prevent the config entry from being unloaded while its platforms are being
setup

* run with error on to find them

* cert_exp, hold lock

* cert_exp, hold lock

* shelly async_late_forward_entry_setups

* compact

* compact

* found another

* patch up mobileapp

* patch up hue tests

* patch up smartthings

* fix mqtt

* fix esphome

* zwave_js

* mqtt

* rework

* fixes

* fix mocking

* fix mocking

* do not call async_forward_entry_setup directly

* docstrings

* docstrings

* docstrings

* add comments

* doc strings

* fixed all in core, turn off strict

* coverage

* coverage

* missing

* coverage
2024-06-04 21:34:39 -04:00
epenet
e58d060f82 Use registry fixtures in tests (s) () 2024-05-28 15:41:03 +02:00
Phil Bruckner
169b9b0bfe Fix removing suggested_display_precision from entity registry ()
* Fix removing suggested_display_precision from entity registry

* Fix tests

* Update homeassistant/components/sensor/__init__.py

---------

Co-authored-by: Erik <erik@montnemery.com>
2024-04-24 16:47:03 +02:00
Richard Kroegel
474a1a3d94 Use display_precision if suggested_display_precision is None ()
Co-authored-by: Richard <rikroe@users.noreply.github.com>
Co-authored-by: Erik Montnemery <erik@montnemery.com>
2024-04-24 09:46:55 +02:00
Sid
9cbed10372 Enable Ruff PYI041 () 2024-04-08 09:29:05 -10:00
Jan-Philipp Benecke
22b14d83e8 Use setup_test_component_platform helper for sensor entity component tests instead of hass.components ()
* Use `setup_test_component_platform` helper for sensor entity component tests instead of `hass.components`

* Missing file

* Fix import

* Remove invalid device class
2024-03-28 12:07:55 +01:00
Sid
00ec7f11f0 Enable Ruff rule PT007 ()
Co-authored-by: Franck Nijhof <frenck@frenck.nl>
2024-03-19 09:01:07 +01:00
Marc Mueller
7d6251ca08 Add empty line after module docstring [tests q-s] () 2024-03-08 14:47:22 +01:00
J. Nick Koston
d9addc45f9 Avoid scheduling a task to add each entity when not using update_before_add ()
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2024-02-23 10:49:26 -10:00
Robert Resch
b409933d19 Add DurationConverter ()
* Add DurationConverter

* Update withings snapshots

* Add sensor test

* Fix tests

* Update snapshots after  was merged
2024-01-30 23:08:12 +01:00
Robert Resch
7d2c6a1bb6 Add check for valid initial_suggested_unit ()
Co-authored-by: Erik Montnemery <erik@montnemery.com>
2024-01-30 18:55:59 +01:00
Joakim Plate
cece117c93 Flow rate unit conversions and device class ()
* Add volume flow rate conversions

* Add missing translations

* Adjust liter unit and add gallons per minute

* Adjust to min instead of m for minutes

* Add matching class for number

* Add some tests for number and sensor platform

* Add deprecated constants

* Add explicit list of flow rate for check

This reverts commit 105171af31.
2024-01-30 15:01:08 +01:00
Jan-Philipp Benecke
80bfd4cef7 Raise ValueError when last_reset set and not total state class ()
* Raise ValueError when last_reset set and not total state class

* Fix test

* Break long string into smaller ones
2024-01-29 20:21:35 +01:00
Erik Montnemery
c805ea7b4f Include deprecated constants in wildcard imports () 2024-01-05 11:46:45 +01:00
Robert Resch
ebdf7b9c8c Deprecate some deprecated const constants ()
* Deprecate some deprecated const constants

* Improve code

* fix typing

* Apply suggestions from code review

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

---------

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2023-12-23 20:18:51 +01:00
Robert Resch
d47ec91231 Deprecate deprecated sensor constants () 2023-12-21 00:02:20 +01:00
Jan Bouwhuis
a66c9bb7b6 Update stale doc strings in entity platform tests () 2023-12-12 08:28:08 +01:00
Robert Resch
f7292d5b00 Add check that sensors don't have EntityCategory.CONFIG set () 2023-10-09 13:37:52 +02:00
Erik Montnemery
17779c5f0c Add loader.async_suggest_report_issue and loader.async_get_issue_tracker ()
* Add loader.async_suggest_report_issue and loader.async_get_issue_tracker

* Update tests

* Add tests

* Address review comments

* Address review comments
2023-10-04 13:40:33 +02:00
Erik Montnemery
d0dc4d0963 Add missing device class to sensor.DEVICE_CLASS_UNITS () 2023-10-02 13:01:26 +02:00
Erik Montnemery
7a1ee98bb6 Fix handling of unit system change in sensor () 2023-09-23 13:28:14 +02:00
Erik Montnemery
bbcbb2e322 Improve Entity._suggest_report_issue () 2023-09-12 21:07:32 +02:00
Erik Montnemery
e3b945a8d0 Don't allow numerical sensor state to be NaN or inf () 2023-08-23 14:16:40 +02:00
Ville Skyttä
2399cd283a Python 3.10 support cleanups () 2023-08-21 19:14:07 +02:00
Miguel Camba
38111141f9 Add new device class: PH (potential hydrogen) () 2023-07-23 18:49:10 +02:00
J. Nick Koston
b24c6adc75 Avoid regex for negative zero check in sensor ()
* Avoid regex for negative zero check in sensor

We can avoid calling the regex for every sensor value
since most of the time values are not negative zero

* tweak

* tweak

* Apply suggestions from code review

* simpler

* cover

* safer and still fast

* safer and still fast

* prep for py3.11

* fix check

* add missing cover

* more coverage

* coverage

* coverage
2023-07-02 21:53:50 -04:00
Erik Montnemery
446a820cbb Name unnamed sensors by their device class () 2023-06-20 23:09:24 +02:00
J. Nick Koston
fba826ae9e Migrate restore_state helper to use registry loading pattern ()
* Migrate restore_state helper to use registry loading pattern

As more entities have started using restore_state over time, it
has become a startup bottleneck as each entity being added is
creating a task to load restore state data that is already loaded
since it is a singleton

We now use the same pattern as the registry helpers

* fix refactoring error -- guess I am tired

* fixes

* fix tests

* fix more

* fix more

* fix zha tests

* fix zha tests

* comments

* fix error

* add missing coverage

* s/DATA_RESTORE_STATE_TASK/DATA_RESTORE_STATE/g
2023-05-30 20:48:17 -05:00
Erik Montnemery
d62cdf3d65 Improve error message for sensors with a non-numeric value ()
* Improve error message for sensors with a non-numeric value

* Address review comment
2023-05-23 15:54:24 +02:00
Erik Montnemery
5a7c3aaa2d Add sensor device class volatile_organic_compounds_parts () 2023-05-12 14:37:54 +02:00
epenet
ab699d17a5 Ensure numeric sensors have a valid value ()
* Ensure numeric sensors have a valid value

* Flake8
2023-03-31 14:12:51 +02:00
Jan Bouwhuis
8968ed1c47 Fix check on non numeric custom sensor device classes ()
* Custom device classes are not numeric

* Update homeassistant/components/sensor/__init__.py

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>

* Add test

* Update homeassistant/components/sensor/__init__.py

Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>

---------

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
2023-03-02 14:20:26 -05:00
Erik Montnemery
fe8f3602ff Fix sensor unit conversion bug ()
* Fix sensor unit conversion bug

* Ensure the correct unit is stored in the entity registry
2023-02-27 11:46:55 +01:00
Franck Nijhof
d3ed8de232 Update Ruff to v0.0.247 ()
* Update Ruff to v0.0.247

* Fix new found violations
2023-02-15 16:46:03 -05:00
epenet
80ee196fd8 Add type hints to integration tests (part 19) () 2023-02-15 18:07:40 +01:00
Gertjan
66ba0cb1d3 Fixed float number validation in sensor component () 2023-02-15 15:53:44 +01:00
Franck Nijhof
ed79265843 Enable Ruff PT006 ()
* Enable Ruff PT006

* Adjust existing cases

* Fix tests

* Remove unneeded parentheses
2023-02-15 14:09:50 +01:00
Erik Montnemery
8f2a764a43 Adjust suggested_display_precision according to unit conversion () 2023-02-13 13:55:12 +01:00
Erik Montnemery
3f910b49ae Fix sensor unit conversion () 2023-02-13 10:08:07 +01:00
epenet
4142f0d15d Add return type to tests without arguments ()
* Add return type to tests without arguments

* Black

* Cancel fixture amends
2023-02-07 14:20:06 +01:00
Erik Montnemery
bcc1aa03b4 Move sensor rounding to frontend ()
* Move sensor rounding to frontend

* Update integrations

* Add comment
2023-02-04 14:54:36 -05:00
Franck Nijhof
bf482eee24 Extend state class sensor warnings with expected values () 2023-02-04 11:49:24 +01:00
Erik Montnemery
4d4fb2477d Optionally update sensor units when unit system is changed () 2023-02-03 16:30:50 +01:00
Jan Bouwhuis
2e16b7e2df Add numeric_state_expected property to Sensor class ()
* Add is_numeric property to Sensor class

* Follw up comment

* Update homeassistant/components/sensor/__init__.py

Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>

* Update homeassistant/components/sensor/__init__.py

Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>

* Tests and corrections

* Simplify converion check

* Correct custom device class handling

* Update homeassistant/components/sensor/__init__.py

Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>

* rename to numeric_state_expected

* Replace with new const

* Adjust docstr

* Update homeassistant/components/sensor/__init__.py

Co-authored-by: Franck Nijhof <frenck@frenck.nl>

* Move to const

* Correct logic

* Do not use bool

* Adjust docstr must be numeric

* remote state from docstr

* protect numeric_state_expected

* Use try_parse_enum for custom class check

* Remove redundant type hints

---------

Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
Co-authored-by: Franck Nijhof <frenck@frenck.nl>
2023-02-01 18:45:13 +01:00