Commit Graph

52 Commits

Author SHA1 Message Date
Arnie97
babc183834 Allow liter for gas sensor device class (#141518) 2025-05-06 10:59:09 +02:00
epenet
7b1b229718 Standardize homeassistant imports in component tests (a-l) (#136806) 2025-01-29 10:00:45 +01:00
epenet
c8797298ea Add missing hass type hint in component tests (e) (#124075) 2024-08-18 15:34:59 +02:00
epenet
cb39d2d16b Ignore existing fixme pylint warnings in tests (#119500)
Co-authored-by: Robert Resch <robert@resch.dev>
2024-06-12 16:40:26 +02:00
epenet
c93d42d59b Add type hints for FrozenDateTimeFactory in test fixtures (#118690) 2024-06-03 10:12:58 +02:00
epenet
092cdcfe91 Improve type hints in tests (a-h) (#118379) 2024-05-30 08:46:18 +02:00
Sid
00ec7f11f0 Enable Ruff rule PT007 (#113764)
Co-authored-by: Franck Nijhof <frenck@frenck.nl>
2024-03-19 09:01:07 +01:00
Sid
69564b1a17 Add ruff rule PIE800 (#113619)
Co-authored-by: J. Nick Koston <nick@koston.org>
2024-03-16 16:31:30 -10:00
Marc Mueller
32f3f46542 Add empty line after module docstring (2) [tests.components] (#112737) 2024-03-08 19:16:21 +01:00
Excentyl
46d626280e Initialize energy_state without price (#97031)
Co-authored-by: Erik <erik@montnemery.com>
2023-12-08 17:46:08 +01:00
Erik Montnemery
b0ef9623f9 Add test for energy cost sensor for late price sensor (#105312) 2023-12-08 16:51:07 +01:00
Jan-Philipp Benecke
81450f0117 Update d-e* tests to use entity & device registry fixtures (#103804) 2023-11-12 10:38:32 +01:00
J. Nick Koston
c6ed022cce Fix compiling missing statistics losing rows (#101616) 2023-10-08 19:43:00 +02:00
Erik Montnemery
28e8fae280 Fix flaky energy tests (#89026) 2023-03-02 12:33:04 +01:00
Erik Montnemery
09f1c2318d Disable gc in-between energy sensor tests (#88593) 2023-03-01 16:21:11 +01:00
Franck Nijhof
d3ed8de232 Update Ruff to v0.0.247 (#88210)
* Update Ruff to v0.0.247

* Fix new found violations
2023-02-15 16:46:03 -05:00
Franck Nijhof
ed79265843 Enable Ruff PT006 (#88165)
* Enable Ruff PT006

* Adjust existing cases

* Fix tests

* Remove unneeded parentheses
2023-02-15 14:09:50 +01:00
epenet
1e352b60df Add type hints to integration tests (part 11) (#87996) 2023-02-13 14:22:49 +01:00
epenet
b9beed4624 Add type hints to integration tests (part 6) (#87979) 2023-02-13 09:45:11 +01:00
Franck Nijhof
ef800335fb Enable Ruff PT022 (#86792)
* Enable Ruff PT022

* Adjust found cases
2023-01-27 13:57:06 +01:00
Michael
2850583085 Replace the usage of unit constants by enumerations in Tests [a-e] (#85932) 2023-01-15 14:44:01 +01:00
Joakim Plate
987e77780a Only run garbage collection per module (#84681)
Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
2023-01-02 09:31:12 -10:00
Joakim Plate
c576a68d33 Upgrade pytest-aiohttp (#82475)
* Upgrade pytest-aiohttp

* Make sure executors, tasks and timers are closed

Some test will trigger warnings on garbage collect, these warnings
spills over into next test.

Some test trigger tasks that raise errors on shutdown, these spill
over into next test.

This is to mimic older pytest-aiohttp and it's behaviour on test
cleanup.

Discussions on similar changes for pytest-aiohttp are here:
https://github.com/pytest-dev/pytest-asyncio/pull/309

* Replace loop with event_loop

* Make sure time is frozen for tests

* Make sure the ConditionType is not async

  /home-assistant/homeassistant/helpers/template.py:2082: RuntimeWarning: coroutine 'AsyncMockMixin._execute_mock_call' was never awaited
    def wrapper(*args, **kwargs):
  Enable tracemalloc to get traceback where the object was allocated.
  See https://docs.pytest.org/en/stable/how-to/capture-warnings.html#resource-warnings for more info.

* Increase litejet press tests with a factor 10

The times are simulated anyway, and we can't stop the normal
event from occuring.

* Use async handlers for aiohttp

tests/components/motioneye/test_camera.py::test_get_still_image_from_camera
tests/components/motioneye/test_camera.py::test_get_still_image_from_camera
tests/components/motioneye/test_camera.py::test_get_stream_from_camera
tests/components/motioneye/test_camera.py::test_get_stream_from_camera
tests/components/motioneye/test_camera.py::test_camera_option_stream_url_template
tests/components/motioneye/test_camera.py::test_camera_option_stream_url_template
  /Users/joakim/src/hass/home-assistant/venv/lib/python3.9/site-packages/aiohttp/web_urldispatcher.py:189: DeprecationWarning: Bare functions are deprecated, use async ones
    warnings.warn(

* Switch to freezegun in modbus tests

The tests allowed clock to tick in between steps

* Make sure skybell object are fully mocked

Old tests would trigger attempts to post to could services:

```
DEBUG:aioskybell:HTTP post https://cloud.myskybell.com/api/v3/login/ Request with headers: {'content-type': 'application/json', 'accept': '*/*', 'x-skybell-app-id': 'd2b542c7-a7e4-4e1e-b77d-2b76911c7c46', 'x-skybell-client-id': '1f36a3c0-6dee-4997-a6db-4e1c67338e57'}
```

* Fix sorting that broke after rebase
2022-11-29 22:36:36 +01:00
Paulus Schoutsen
a8c527f6f3 Add unit conversion for energy costs (#81379)
Co-authored-by: Franck Nijhof <git@frenck.dev>
2022-11-02 12:18:50 +01:00
Erik Montnemery
95fc641949 Add support to the energy integration for tracking water usage (#80888) 2022-10-26 21:20:52 +02:00
epenet
842cb18d39 Migrate energy units to an enum (#80998) 2022-10-26 13:56:51 +02:00
Erik Montnemery
727eccfec4 Add GJ as supported unit for energy sensors (#80870)
* Add GJ as supported unit for energy sensors

* Update homeassistant/const.py

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

Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
2022-10-25 16:43:00 +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
Erik Montnemery
6b0c9b6a6a Simplify energy settings (#78947) 2022-09-22 21:58:15 -04:00
Erik Montnemery
8a9edea2c1 Fix calculating gas cost for gas measured in ft3 (#78327) 2022-09-12 21:24:49 -04:00
Erik Montnemery
1aaf78ef99 Remove entity category system in favor of hidden_by (#68550) 2022-05-02 09:33:16 -07:00
Franck Nijhof
5c1be2f99d Add unique ID to energy sensors (#70378) 2022-04-26 23:14:16 -07: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
J. Nick Koston
3737b58e85 Avoid fetching metadata multiple times during stat compile (#70397) 2022-04-22 00:25:42 -10:00
Erik Montnemery
949b0e1b65 Don't allow in-memory SQLite database (#69616) 2022-04-08 00:43:09 +02:00
Dave T
f92baffd09 Use DeviceClass Enums in energy tests (#62122) 2021-12-16 23:40:24 +01:00
Erik Montnemery
f228537458 Fix energy cost sensor for MWh + improve tests (#58540) 2021-10-27 19:07:05 +02:00
Colin Robbins
39998f5387 Add kWh as cost option for gas (#58426)
* Add kWh as cost option for GAS

* Add kWh as cost option for GAS (pylint)

* Add kWh as cost option for GAS (make CONST)

* Change GAS_UNITS to VALID_ENERGY_UNITS

* Add test for Gas cost in kWh (2)

* Back off ENERGY_WATT_HOUR - unlikely for gas

* Add MEGA_WATT_HOUR support (2)

* Normalise pricing for MEGA_WATT_HOUR

* Normalise pricing for MEGA_WATT_HOUR
2021-10-27 18:06:32 +02:00
Erik Montnemery
f594bc353b Add support for external statistics (#56607)
* Support external statistics

* Update tests

* Lint

* Adjust code after rebase

* Separate external statistic_id with :, add name to metadata

* Adjust tests

* Simplify get_metadata_with_session

* Address review comments

* Allow updating external statistics

* Validate input

* Adjust tests after rebase

* Pylint

* Adjust tests

* Improve test coverage
2021-10-26 10:26:50 +02:00
Erik Montnemery
92253f5192 Minor refactoring of periodic statistics (#56492) 2021-09-22 13:31:33 -07:00
Erik Montnemery
78909b5227 Add support for state class total to energy cost sensor (#55955)
* Add support for all state classes to energy cost sensor

* Fix bug, adjust tests

* Fix rebase mistake
2021-09-10 09:05:32 +02:00
Erik Montnemery
bb6c2093a2 Add support for state class measurement to energy cost sensor (#55962) 2021-09-08 12:46:28 -07:00
Erik Montnemery
b99a22cd4d Re-add state_class total to sensor (#55103)
* Re-add state_class total to sensor

* Make energy cost sensor enforce state_class total_increasing

* Bump deprecation of last_reset for state_class measurement

* Correct rebase mistakes
2021-09-06 18:28:58 +02:00
Paulus Schoutsen
1e05c81fe6 Fix recorder test (#55169)
Co-authored-by: Erik <erik@montnemery.com>
2021-08-25 08:48:13 +02:00
Erik Montnemery
fa9f91325c Allow small dip in total_increasing sensor without detecting a reset (#55153) 2021-08-24 17:23:55 +02:00
Erik Montnemery
8877f37da0 Fix statistics for sensors setting last_reset (#55136)
* Re-add state_class total to sensor

* Make energy cost sensor enforce state_class total_increasing

* Drop state_class total

* Only report energy sensor issues once
2021-08-24 17:02:34 +02:00
Erik Montnemery
e1926caeb9 Remove STATE_CLASS_TOTAL and last_reset from sensor (#54755)
* Remove STATE_CLASS_TOTAL

* Update mill sensor

* Update tests

* Kill last_reset

* Return ATTR_LAST_RESET to utility_meter

* Update energy cost sensor

* Restore last_reset for backwards compatibility

* Re-add and update deprecation warning

* Update tests

* Fix utility_meter

* Update EnergyCostSensor

* Tweak

* Fix rebase mistake

* Fix test
2021-08-18 10:03:27 +02:00
Bram Kragten
eb278834de Add gas support to energy (#54560)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2021-08-13 10:39:16 -07:00
Paulus Schoutsen
2cbcd5f2a9 Cost sensor handle consumption sensor in Wh (#53746) 2021-07-30 11:00:52 +02:00