Commit Graph

46 Commits (9f885a68ff7495fadc891122272223f166d2e3c7)

Author SHA1 Message Date
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
Thomas Dietrich b8f4b76194
Add additional statistics characteristics, remove attributes (#59867)
* Add additional statistics characterics, improve rounding

* Improve name of age_usage_ratio

* Replace difference by three relevant distances

* Refactor attributes, remove stats, add metadata

* Fix binary sensor testcase

* Fix sensor defaults testcase

* Fix and enhance all testcases

* Remove age coverage from attr when not configured

* Refactor so only the relevant characteristic value is calculated

* Rename unclear characteristics, add timebound average

* Fix coverage warning

* Remove explicit functions dict
2021-11-24 13:42:44 +01:00
Thomas Dietrich 0ab3b10aed
Allow selection of statistics state characteristic (#49960)
* Make statistics state characteristic selectable

* Move computation in helper function

* Add relevant config elements for clarity

* Rename variables for better readability

* Avoid reserved prefix ATTR_ for stats

* Fix NoneType base_unit error

* Add testcases for statistics characteristic

* Add testcases for state_class, unitless, and characteristics

* Add testcase coverage for no unit with binary

* Replace error catching by an exception

* Attend to review comments
2021-11-17 12:31:32 +01:00
Thomas Dietrich 90ee1f4783
Add available property to statistics component (#59203)
* Add available property to the statistics component

* Add test for statistics sensor availability

* Clean up availability check

* Improve statistics source sensor tests

* Revert variable rename

* Improve comments
2021-11-11 17:16:59 +01:00
Thomas Dietrich 9eaf8bd21b
Fix statistics precision handling (#59202)
* Fix statistics precision error when configured 0, fix #42547

* Add tests for statistics precision

* Apply precision=0 logic to float numbers only

* Implement contextlib way of exception handling
2021-11-08 23:26:00 +01:00
Thomas Dietrich 2924f4605b
Fix statistics startup error for None value states (#59199)
* Catch statistics startup error for None value states, fix #49254

* Add test for statistics None handling

* Update tests/components/statistics/test_sensor.py

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

* Switch test case logic to remove sensor last

Co-authored-by: Erik Montnemery <erik@montnemery.com>
2021-11-08 23:25:19 +01:00
Paulus Schoutsen 31153ac155
Move fixtures part 1 (#58902) 2021-11-01 20:47:05 -07:00
Erik Montnemery 398061706c
Correct unit_of_measurement for statistics sensor (#58023) 2021-10-20 20:28:48 +02:00
Carlos Gomes f2906d0fca
Add quantiles to Statistics integration (#52189)
* Add quantiles as another Statistics attribute

Quantiles divide states into intervals of equal probability. The
statistics.quantiles() function was added in Python 3.8 and can now
be included in the Statistics integration without new dependencies.

Quantiles can be used in conjunction with other distribution metrics to
create box plots (quartiles) and other graphical resources for
visualizing the distribution of states.

* Add quantiles reference to basic tests
2021-06-30 08:31:33 +02:00
Franck Nijhof 5a2b5fe7c5
Yoda assertion style removed is (#48142) 2021-03-20 13:55:10 +01:00
Franck Nijhof 65cf2fcb6f
Drop asynctest (#44746) 2021-01-01 22:31:56 +01:00
Ville Skyttä 5e90a4d000
Use more state attribute name constants (#40428) 2020-09-21 23:03:39 +02:00
Franck Nijhof 1c2ebdf307
Upgrade black to 20.8b1 (#39287) 2020-08-27 13:56:20 +02:00
J. Nick Koston dc84196202
Add the ability to reload statistics platforms from yaml (#39268) 2020-08-26 14:52:19 +02:00
J. Nick Koston b430496b13
Switch async_track_state_change to the faster async_track_state_change_event part 4 (#37863)
* Switch async_track_state_change to the faster async_track_state_change_event part 4

Calling async_track_state_change_event directly is faster than async_track_state_change (see #37251) since async_track_state_change is a wrapper around async_track_state_change_event now

* pylint
2020-07-14 22:25:48 -07:00
J. Nick Koston 89a9634d35
Use eventloop for scheduling (#37184)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2020-06-29 09:39:24 -07:00
J. Nick Koston edad387b12
Make recorder execute avoid native conversion by default (#36938) 2020-06-21 21:58:57 -07:00
Paulus Schoutsen 276f3afb00
Do async_setup_platform in background (#36244)
Co-authored-by: J. Nick Koston <nick@koston.org>
2020-05-31 22:18:30 -07:00
Paulus Schoutsen 2af984917e
Use asynctest-mock in most places (#35109)
* Use asynctest-mock in most places

* Fix broken patch in pilight
2020-05-03 11:27:19 -07:00
springstan 78d87dc40f
Use TEMP_CELSIUS constant (#33963) 2020-04-10 19:17:46 +02:00
Florian Werner 5216dc0ae1
Fix rate of change calculation of statistics sensor (#32597)
* Fix rate of change of statistics sensor

* Fix test
2020-03-11 09:33:00 -07:00
Malte Franken 4149bd653d Fix statistics sensor honouring max_age (#27372)
* added update listener if max_age is set

* remove commented out code

* streamline test code

* schedule next update based on the next state to expire

* fixed update process

* isort

* fixed callback function

* fixed log message

* removed logging from test case
2020-01-09 14:03:27 +01:00
Bas Nijholt 23b92b2a56 Sort imports according to PEP8 for components starting with "S" (#29777) 2019-12-09 14:38:01 +01:00
Franck Nijhof 12f964ca57 Statistics sensors repect given name (#26119) 2019-08-21 15:54:04 -07:00
Paulus Schoutsen 4de97abc3a Black 2019-07-31 12:25:30 -07:00
Jason Hu 388d614e30 Ignore flaky test (#22563) 2019-03-30 21:10:32 -07:00
Penny Wood f195ecca4b Consolidate all platforms that have tests (#22109)
* Moved climate components with tests into platform dirs.

* Updated tests from climate component.

* Moved binary_sensor components with tests into platform dirs.

* Updated tests from binary_sensor component.

* Moved calendar components with tests into platform dirs.

* Updated tests from calendar component.

* Moved camera components with tests into platform dirs.

* Updated tests from camera component.

* Moved cover components with tests into platform dirs.

* Updated tests from cover component.

* Moved device_tracker components with tests into platform dirs.

* Updated tests from device_tracker component.

* Moved fan components with tests into platform dirs.

* Updated tests from fan component.

* Moved geo_location components with tests into platform dirs.

* Updated tests from geo_location component.

* Moved image_processing components with tests into platform dirs.

* Updated tests from image_processing component.

* Moved light components with tests into platform dirs.

* Updated tests from light component.

* Moved lock components with tests into platform dirs.

* Moved media_player components with tests into platform dirs.

* Updated tests from media_player component.

* Moved scene components with tests into platform dirs.

* Moved sensor components with tests into platform dirs.

* Updated tests from sensor component.

* Moved switch components with tests into platform dirs.

* Updated tests from sensor component.

* Moved vacuum components with tests into platform dirs.

* Updated tests from vacuum component.

* Moved weather components with tests into platform dirs.

* Fixed __init__.py files

* Fixes for stuff moved as part of this branch.

* Fix stuff needed to merge with balloob's branch.

* Formatting issues.

* Missing __init__.py files.

* Fix-ups

* Fixup

* Regenerated requirements.

* Linting errors fixed.

* Fixed more broken tests.

* Missing init files.

* Fix broken tests.

* More broken tests

* There seems to be a thread race condition.
I suspect the logger stuff is running in another thread, which means waiting until the aio loop is done is missing the log messages.
Used sleep instead because that allows the logger thread to run. I think the api_streams sensor might not be thread safe.

* Disabled tests, will remove sensor in #22147

* Updated coverage and codeowners.
2019-03-18 23:07:39 -07:00