Commit Graph

119 Commits

Author SHA1 Message Date
Dave T
1a0abe296c Remove deprecated conductivity constants (#153942) 2025-10-07 23:20:36 +01:00
Erik Montnemery
7f63ba2087 Improve saved state of RestoreSensor when using freezegun (#152740) 2025-09-30 18:27:56 +02:00
Erik Montnemery
5975cd6e09 Revert "Add mg/m³ as a valid UOM for sensor/number Carbon Monoxide device class" (#153196) 2025-09-29 15:43:13 +01:00
Simon Roberts
ec148e0459 Add PM4 (particulates < 4μm) sensor and number device classes (#112867)
Co-authored-by: Erik Montnemery <erik@montnemery.com>
Co-authored-by: J. Nick Koston <nick@home-assistant.io>
2025-09-19 08:12:09 -06:00
Jan Bouwhuis
5eef6edded Add mg/m³ as a valid UOM for sensor/number Carbon Monoxide device class (#152456) 2025-09-17 22:04:23 +01:00
epenet
56c865dcfe Fix _is_valid_suggested_unit in sensor platform (#151912) 2025-09-08 16:35:33 +02:00
Jan Bouwhuis
48300f4563 Use greek small letter mu "\u03bc" instead of micro sign "\u00B5" for micro unit prefix (alt 1) (#144853)
Co-authored-by: Erik Montnemery <erik@montnemery.com>
2025-08-19 18:48:50 +02:00
Ludovic BOUÉ
cc4b9e0eca Extend UnitOfReactivePower with 'mvar' (#150415) 2025-08-14 11:46:06 +02:00
Ludovic BOUÉ
eb4b75a9a7 Extend UnitOfApparentPower with 'mVA' (#150422)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2025-08-13 15:56:04 +02:00
epenet
de4a5fa30b Remove unnecessary DOMAIN alias in tests (s-z) (#146010) 2025-06-02 08:48:37 +02:00
epenet
c3ade400fb Use Platform constant in tests (#145801)
* Use Platform constant in tests

* spelling

* Fix platform
2025-05-28 15:51:37 +02:00
Abílio Costa
b626204f63 Add default device class display precision for Sensor (#145013)
* Add default device class display precision for Sensor

* Renaming, docstrings, cleanup

* Simplify units list

* Fix tests

* Fix missing precision when suggested is specified

* Update snapshots

* Fix when unit of measurement is not valid

* Fix tests

* Fix deprecated unit usage

* Fix goalzero tests

The sensor native_value method was accessing the data dict and trowing,
since the mock did not have any data for the sensors.

Since now the precision is always specified (it was missing for those
sensors), the throw was hitting async_update_entity_options in _update_suggested_precision.
Previously, async_update_entity_options was not called since it had no
precision.

* Fix metoffice

* Fix smartthings

* Add default sensor data for Tesla Wall Connector tests

* Update snapshots

* Revert spaces

* Update smartthings snapshots

* Add missing sensor mock for tesla wall connector

* Address review comments

* Add doc comment

* Add cap to doc comment

* Update comment

* Update snapshots

* Update comment
2025-05-26 19:40:29 +02:00
Abílio Costa
54dce53628 Add sensor tests for device class enums (#145523) 2025-05-26 14:28:30 +01:00
alorente
1d47dc41c9 Add reactive energy device class and units (#143941) 2025-05-15 12:05:46 +01:00
Robert Resch
f842640249 Add check that sensor state classes are used only with valid unit of measurements (#141444) 2025-03-26 13:52:00 +01:00
Erik Montnemery
428cc1a951 Update signature of platforms' async_setup_entry in tests (#138271) 2025-02-11 13:17:39 +01:00
Joost Lekkerkerker
53ad02a1eb Enable RUF032 (#135836) 2025-01-20 08:05:33 +01:00
Joost Lekkerkerker
8a35261fd8 Remove unused noqas (#135583) 2025-01-15 10:02:18 +01:00
Abílio Costa
6db8fced60 Update buienradar sensors only after being added to HA (#131830)
* Update buienradar sensors only after being added to HA

* Move check to util

* Check for platform in sensor state property

* Move check to unit translation key property

* Add test for sensor check

* Properly handle added_to_hass

* Remove redundant comment
2024-12-02 13:52:59 +01:00
Robert Resch
1f9ecfe839 Remove deprecated sensor constants (#131843) 2024-11-28 20:49:49 +01:00
Robert Resch
a67045ee6c Remove deprecated home assistant const constants (#131799) 2024-11-28 12:12:37 +01:00
Abílio Costa
e4e9d76b45 Raise error if sensor has translated and hardcoded unit (#131657) 2024-11-27 17:45:53 +01:00
Abílio Costa
d8dd6a99b3 Use default translation on SensorEntity unit_of_measurement (#131633)
* Use translations on SensorEntity unit_of_measurement property

* Use default language for unit translation

* Update brother integration snapshot

* Update snapshots
2024-11-27 14:45:53 +01:00
Michael Arthur
d8549409f7 Area units and conversion between metric and US (#123563)
* area conversions

* start work on tests

* add number device class

* update unit conversions to utilise distance constants

* add area unit

* update test unit system

* update device condition and trigger

* update statistic unit converters

* further tests work WIP

* update test unit system

* add missing string translations

* fix websocket tests

* add deprecated notice

* add more missing strings and missing initialisation of unit system

* adjust icon and remove strings from scrape and random

* Fix acre to meters conversion

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

* Tidy up valid units

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

* fix ordering of area

* update order alphabetically

* fix broken test

* update test_init

* Update homeassistant/const.py

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

* remove deprecated unit and fix alphabetical order

* change deprecation and add tests, change to millimeter conversion for inches

* fix order

* re-order defs alphabetically

* add measurement as well

* update icons

* fix up Deprecation of area square meters

* Update core integrations to UnitOfArea

* update test recorder tests

* unit system tests in alphabetical

* update snapshot

* rebuild

* revert alphabetization of functions

* other revert of alphabetical order

---------

Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
2024-11-21 16:10:44 +01:00
Richard Kroegel
865190f0b0 Get suggested_unit_of_measurement via unit converter's UNIT_CLASS (#119196)
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) (#120917) 2024-07-01 11:54:42 +02:00
Joost Lekkerkerker
0fdf037ba0 Fix ruff type comparison E721 (#120731)
Fix E721
2024-06-28 11:56:49 +02:00
G Johansson
b59e7ede9a Raise on incorrect suggested unit for sensor (#120180) 2024-06-22 22:05:45 +02:00
epenet
2e3c3789d3 Use relative imports in tests [s-z] (#119283) 2024-06-10 13:33:15 +02:00
Marc Mueller
837ee7c4fb Import Generator from typing_extensions (4) (#118992) 2024-06-06 17:41:37 +02:00
J. Nick Koston
ed0568c655 Ensure config entries are not unloaded while their platforms are setting up (#118767)
* 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) (#118295) 2024-05-28 15:41:03 +02:00
Phil Bruckner
169b9b0bfe Fix removing suggested_display_precision from entity registry (#110671)
* 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 (#110270)
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 (#115229) 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 (#114316)
* 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 (#113764)
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] (#112711) 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 (#110951)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2024-02-23 10:49:26 -10:00
Robert Resch
b409933d19 Add DurationConverter (#108865)
* Add DurationConverter

* Update withings snapshots

* Add sensor test

* Fix tests

* Update snapshots after #108902 was merged
2024-01-30 23:08:12 +01:00
Robert Resch
7d2c6a1bb6 Add check for valid initial_suggested_unit (#108902)
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 (#106077)
* 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 (#108391)
* 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 (#107114) 2024-01-05 11:46:45 +01:00
Robert Resch
ebdf7b9c8c Deprecate some deprecated const constants (#106230)
* 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 (#106120) 2023-12-21 00:02:20 +01:00
Jan Bouwhuis
a66c9bb7b6 Update stale doc strings in entity platform tests (#105526) 2023-12-12 08:28:08 +01:00
Robert Resch
f7292d5b00 Add check that sensors don't have EntityCategory.CONFIG set (#101471) 2023-10-09 13:37:52 +02:00
Erik Montnemery
17779c5f0c Add loader.async_suggest_report_issue and loader.async_get_issue_tracker (#101336)
* 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 (#101256) 2023-10-02 13:01:26 +02:00