76 Commits

Author SHA1 Message Date
Erik Montnemery 2434341e04 Queue nested firing of events (#173519) 2026-06-15 17:27:16 +02:00
Franck Nijhof 5b2816e56c Fix line length violations in tests/components s (#170990)
Co-authored-by: Simone Chemelli <simone.chemelli@gmail.com>
2026-05-17 17:14:26 -04:00
epenet 88525955ce Remove import annotations from tests (#169527) 2026-04-30 09:30:46 +02:00
epenet 7bb0414a39 Remove outdated device registry cleanup in statistics (#161865) 2026-01-31 15:14:09 +01:00
epenet dbfdaf6a2e Use is over == comparison for FlowResultType in flow tests (#159158) 2025-12-16 09:48:45 +01:00
Erik Montnemery b59d8b5730 Improve statistics sensor tests (#149181) 2025-07-21 13:20:04 +02:00
Erik Montnemery d72fb021c1 Improve statistics tests (#148937) 2025-07-17 11:42:25 +02:00
Erik Montnemery 3cb579d585 Do not add statistics config entry to source device (#148731) 2025-07-15 22:13:26 +02:00
Erik Montnemery cb9c213496 Handle changes to source entity in statistics helper (#146523) 2025-06-11 15:17:19 +02:00
epenet de4a5fa30b Remove unnecessary DOMAIN alias in tests (s-z) (#146010) 2025-06-02 08:48:37 +02:00
Simone Chemelli 484a547758 Fix pylance warning on SnapshotAssertion import (#145206) 2025-05-19 13:55:48 +02:00
G Johansson 50cc6b4e01 Use shorthand attribute for extra state attributes in statistics (#129353) 2024-11-15 17:37:57 +01:00
G Johansson 7d699c6c35 Fix calculation of attributes in statistics (#128475)
* Fix calculation of attributes in statistics

* Cleanup

* Mods

* Fix device class

* Typing

* Mod uom calc

* Fix UoM

* Fix docstrings

* state class docstring
2024-10-28 19:45:47 +01:00
unfug-at-github 50ccce7387 React to state report events to increase sample size of statistics (#129211)
* react to state reported events to increase sample size

* added test case for timinig and minor corrections
2024-10-28 14:41:48 +01:00
unfug-at-github c5ed148c52 Fix race condition in statistics that created spikes (#129066)
* fixed race condition and added test case for updates before db load

* removed duplicated code

* improved comments, removed superfluous errors / assertions

* allow both possible outcomes of race condition

* use approx for float comparison

* Update tests/components/statistics/test_sensor.py

Co-authored-by: Erik Montnemery <erik@montnemery.com>

* force new state before database load in race condition test

---------

Co-authored-by: Erik Montnemery <erik@montnemery.com>
2024-10-26 09:23:47 +02:00
unfug-at-github 9ec4881d8d Have statistics functions return a meaningful, non-none result even if only one value is available (#127305)
* have statistics functions return a meaningful, non-none result even if only one value is available

* improved code coverage
2024-10-23 16:02:46 +02:00
G Johansson 2ff88e7baf Add preview to statistics (#122590) 2024-09-27 21:09:42 +02:00
dougiteixeira 4437c4a204 Link the Statistics helper entity to the source entity device (#120705) 2024-06-28 12:22:24 +02:00
G Johansson 3d5d4f8ddb Add config flow to statistics (#120496) 2024-06-26 16:06:35 +02:00
epenet 4962895f19 Fix consider-using-enumerate warnings in tests (#119506) 2024-06-12 16:27:56 +02:00
epenet e58d060f82 Use registry fixtures in tests (s) (#118295) 2024-05-28 15:41:03 +02:00
Sid ac54cdcdb4 Enable Ruff RUF010 (#115371)
Co-authored-by: J. Nick Koston <nick@koston.org>
2024-05-08 23:54:49 +02:00
Joost Lekkerkerker 6bb4e7d62c Bump ruff to 0.3.4 (#112690)
Co-authored-by: Sid <27780930+autinerd@users.noreply.github.com>
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
Co-authored-by: J. Nick Koston <nick@koston.org>
2024-03-26 00:02:16 +01:00
Joost Lekkerkerker 77917506bb Improve lists in integrations [R-S] (#113233)
* Improve lists in integrations [R-S]

* Fix

* Fix
2024-03-13 21:55:00 +01:00
Marc Mueller 7d6251ca08 Add empty line after module docstring [tests q-s] (#112711) 2024-03-08 14:47:22 +01:00
Brenan Kelley 458c5ae657 Add statistics keep_last_sample option (#88655)
* introduce preserve last value option

* improve comments

* add unit test

* skip scheduling purge on a preserved value

* do not schedule sensor update if preserving last value

* fix unit test to use new mock time pattern

pattern introduced in https://github.com/home-assistant/core/pull/93499

* rename preserve_last_val to keep_last_sample

* add keep_last_sample config validation
2024-02-27 13:17:05 +01:00
enzo2 35be5957c3 Add circular mean to statistics integration (#98930)
* Add circular mean

Add support for circular mean for sensors in units of degrees, e.g. direction data.

* Update test_sensor.py

* Update sensor.py

* Remove whitespace

* Revert to degC

* Fix: shift atan2 output to positive degrees

* Add new dedicated test

* Simplify test
2023-10-07 13:51:27 +02:00
J. Nick Koston 790c1bc251 Decrease event loop latency by binding time.monotonic to loop.time directly (#98288)
* Decrease event loop latency by binding time.monotonic to loop.time directly

This is a small improvment to decrease event loop latency. While the goal is
is to reduce Bluetooth connection time latency, everything using asyncio
is a bit more responsive as a result.

* relo per comments

* fix too fast by adding resolution, ensure monotonic time is patchable by freezegun

* fix test that freezes time too late and has a race loop
2023-08-13 20:37:45 -04:00
J. Nick Koston f8d8f5caba Update statistics tests to avoid patching utcnow (#93499) 2023-05-24 17:38:38 -05:00
J. Nick Koston 1f5916cb4d Update statistics tests to avoid patching utcnow (#93485) 2023-05-24 14:53:33 -05:00
epenet dab8557951 Add type hints to integration tests (part 21) (#88233) 2023-02-16 11:15:26 +01:00
Thomas Dietrich a0e0feb444 Statistics component fix device_class for incremental source sensors (#88096)
* Return None device_class for incremental source sensors

* Ignore linting error

* Fix ignore linting error

* Fix ignore linting error

* Fix ignore linting error

* Catch potential parsing error with enum
2023-02-15 10:22:09 +01:00
Franck Nijhof e50a531cd9 Code styling tweaks to the tests - Part 2 (#86662)
Co-authored-by: jjlawren <jjlawren@users.noreply.github.com>
2023-01-26 01:23:53 +01:00
Michael 9709391b52 Replace the usage of unit constants by enumerations in Tests [s-u] (#85937) 2023-01-16 09:00:27 +01:00
Thomas Dietrich ad8b882cb6 Switch statistics config to require either/both 'max_age' and 'sampling_size' (#80999)
* Remove default characteristic

* Remove default sampling_size

* Fix typo

* Fix typo
2022-11-17 10:31:06 +01:00
Thomas Dietrich a0b0e4088c Replace quantiles by percentile characteristic for statistics component (#81027)
* Remove quantiles characteristic

* Add percentile characteristic
2022-11-14 09:23:02 +01:00
Thomas Dietrich 3346ddcd86 Add sum-differences characteristics to statistics component (#79439) 2022-10-25 16:46:47 +02:00
Erik Montnemery 31a787558f Ensure recorder test fixture is setup before hass fixture (#80528)
* Ensure recorder test fixture is setup before hass fixture

* Adjust more tests
2022-10-19 07:58:47 +02:00
Thomas Dietrich f2d6a06a6a Add additional characteristics to the statistics integration (#62631)
* Improve config checking, add device_class timestamp

* Improve warning message
2022-05-04 15:57:56 +02:00
Thomas Dietrich 9fdec407e0 Provide statistics device_class based on source entity and characteristic (#69710) 2022-04-26 12:12:47 -10:00
Erik Montnemery 28ebab9c5a Simplify waiting for recorder in tests (#70647) 2022-04-25 12:04:47 +02:00
Erik Montnemery 982e314de6 Use recorder_mock in tests (#70363)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2022-04-22 19:29:44 -10:00
Marc Mueller d057850971 Update typing - collections.abc (3) (#63947) 2022-01-12 08:04:17 +01:00
Thomas Dietrich dc15c9ed75 Add SensorDeviceClass to statistics component, improve structures (#62629)
* Improve config checking, add device_class timestamp

* Move additional characteristics into separate branch

* Move deprecation warning for sampling_size default to other branch

* Add supports list description
2022-01-04 10:25:37 +01:00
Thomas Dietrich 28af0b4092 Statistics component typing (#60997)
* Implement optional manually defined uniqueid

* Fix test case via mocked environment

* Add typing to statistics component

* Fix minor inconsistency

* Fix linter issues

* Execute hassfest

* Fix stricter mypy warnings

* Fix maxsplit warning

* Make binary value range explicit check

* Add basic typing to statistics tests

* Add empty config testcase

* Minor improvements

* Improve after comments

* Remove unnecessary test case

* Fix changed type

* Remove dict.get default
2021-12-20 14:53:51 +01:00
Robert Hillis af631b90e5 Use enums in statistics tests (#62191) 2021-12-18 14:54:26 +01:00
Thomas Dietrich bbe6d3c9ae Statistics refactor testcases in async pytest style (#60935)
* Implement optional manually defined uniqueid

* Fix test case via mocked environment

* Refactor testcases

* Fix missing awaits

* Revert order changes, reduce use of block command

* Tidy up mocked time testcases
2021-12-08 16:53:18 +01:00
Thomas Dietrich 6d6e0dd8bf Add unique_id to the statistics component (#59205)
* Implement optional manually defined uniqueid

* Fix test case via mocked environment
2021-12-04 09:50:47 +01:00
Thomas Dietrich bee3c9102c Add binary characteristics, add deprecation warning for optional state_characteristic parameter (#60402)
* Add binary source sensor statistics

* Make state_characteristic a required parameter

* Move binary unitless testcase

* Add testcases for binary characteristics

* Revert charact. to optional with deprecation warning

* Correctly check for binary supported characteristic
2021-12-02 09:03:24 +01:00
Thomas Dietrich 4c0d90ed41 Remove unknown attribute instead of marking STATE_UNKNOWN (#60325) 2021-11-25 15:13:55 +01:00