Commit graph

325 commits

Author SHA1 Message Date
Erik Montnemery 045c327928
Move DeviceInfo from entity to device registry (#98149)
* Move DeviceInfo from entity to device registry

* Update integrations
2023-08-10 22:04:26 -04:00
Erik Montnemery 0317afeb17
Fix mock_integration and mock_platform test helpers (#98109) 2023-08-09 15:38:57 +02:00
J. Nick Koston 094f2cbad7
Fix saving subclassed datetime objects in storage (#97502) 2023-07-31 18:49:02 +02:00
Paulus Schoutsen 5f14cdf69d
Allow stopping a script with a response value (#95284) 2023-06-27 08:24:22 +02:00
Erik Montnemery 8fda56d2c9
Stable entity registry id when a deleted entity is restored (#77710)
* Stable entity_id and registry id when a deleted entity is restored

* Don't restore area_id

* Don't restore entity_id

* Address review comments
2023-06-26 15:54:35 +02:00
J. Nick Koston c1045d6c82
Fix hass_storage not clearing task (#95209)
hass_storage would never allow another load if the
no data path was hit

discovered while writing tests for https://github.com/home-assistant/core/pull/95202
2023-06-25 19:54:02 -04:00
Erik Montnemery 732ce34a66
Remove assert_lists_same test helper (#94904) 2023-06-21 12:10:28 +02:00
Allen Porter 12129e9d21
Update service call return values and error handling (#94657)
* Update return signature of service calls

* Add timeout error handling in websocket api for service calls

* Update recorder tests to remove assertion on service call

* Remove timeout behavior and update callers that depend on it today

* Fix tests

* Add missing else

* await coro directly

* Fix more tests

* Update the intent task to use wait instead of timeout

* Remove script service call limits and limit constants

* Update tests that depend on service call limits

* Use wait instead of wait_for and add test

* Update homeassistant/helpers/intent.py

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

---------

Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2023-06-16 07:01:40 -07:00
J. Nick Koston 34b725bb99
Debounce discoveries to improve event loop stability at the started event (#94690)
* Debounce discoveries to improve event loop stability at the started event

The first one is immediate and anything that fires within the next
second will be debounced to only happen once every second

* fix mock
2023-06-15 22:15:07 -04:00
J. Nick Koston a0c023d5cb
Reduce overhead to lookup items in the entity and device registry (#94568) 2023-06-14 20:47:18 +02:00
J. Nick Koston fba826ae9e
Migrate restore_state helper to use registry loading pattern (#93773)
* 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
Ville Skyttä c7c4ee13c3
Import util.dt as dt_util in remaining tests, enforce with ruff (#93765)
* Import `util.dt` as `dt_util` in remaining tests, enforce with ruff

* Fix `util.dt` import in pvpc_hourly_pricing tests
2023-05-30 23:30:31 +03:00
J. Nick Koston 48485fc2bf
Complete persistent notifications migration (#92828)
* Complete migration of persistent notifications

Persistent notifications are no longer stored in
the state machine and no longer fire events

* Complete migration of persistent notifications

Persistent notifications are no longer stored in
the state machine and no longer fire events

* fixes

* fixes

* fixes

* ws test

* update tests

* update tests

* fix more tests

* fix more tests

* more fixes

* fix

* fix person

* fix person

* keep whitelist

* use singleton
2023-05-25 23:09:13 -04:00
Paulus Schoutsen 6e4c78686e
Run pipeline from audio stream function (#90748)
* Run pipeline from audio stream function

* Fix tests

---------

Co-authored-by: Michael Hansen <mike@rhasspy.org>
2023-04-04 00:06:51 -04:00
Erik Montnemery 0ecd043cb2
Add test helper mock_config_flow (#90103) 2023-03-22 08:59:35 -04:00
epenet abd91dd934
Ensure MockEntityPlatform shuts down after tests (#89849) 2023-03-17 10:22:43 +01:00
J. Nick Koston 11681f3f31
Pass a helpful name when creating common asyncio tasks in core (#89171) 2023-03-05 12:46:02 +01:00
epenet 1bed5c7775
Adjust registry access in tests root (#88880) 2023-02-28 21:56:46 -05:00
Erik Montnemery 83e5bf7ae8
Use entity_sources to determine integration in recorder platforms (#88382) 2023-02-18 07:21:41 -06:00
epenet 185cd61cbd
Add type hints to integration tests (recorder) (#88313) 2023-02-17 18:50:09 +01:00
epenet 8c821c8969
Add JSON support to load_fixture (#88076)
* Add JSON support to load_fixture

* More tests

* Remove lru_cache on load_json
2023-02-16 19:40:47 +01:00
Paulus Schoutsen d54f59478f
Keep task references while running (#87970)
* Keep task references while running

* Update pilight tests pointing at correct logger call

* Fix graphite tests

* Fix profiler tests

* More graphite test fixes

* Remove extra sleep

* Fix tests

* Shutdown background tasks as part of stage 1

* Remove unnecessary sleep in test

* Remove unused method on mock hass

* Skip on cancelled too

* Remove background tasks

* Test trigger variables without actually sleeping

* Fix graphite

* One more graphite grrrrrrr
2023-02-13 23:16:59 -05:00
Jan Bouwhuis 950ee34514
Correct typing on hass_storage fixure (#87986)
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
2023-02-13 12:12:34 +01:00
Paulus Schoutsen f9dc562251
Stub I/O when loading registries in tests (#87744) 2023-02-09 08:25:52 +01:00
Franck Nijhof 6551eb168d
Add common area, device, entity and issue registry test fixtures (#87694) 2023-02-08 16:28:44 +01:00
Franck Nijhof 20b60d57f2
Add lru cache to loading fixtures in tests (#87634) 2023-02-07 16:50:13 +01:00
Jan Bouwhuis 3edfd10f2d
Add type hints for MQTT common helper and fixtures (#87065) 2023-02-03 19:27:46 +01:00
Franck Nijhof 3b5fd4bd06
Enable Ruff TRY004 (#86811) 2023-01-30 14:06:52 +01:00
epenet 30bf0634fe
Add per-file-ignore to pylint (#86289) 2023-01-22 17:26:24 +01:00
Franck Nijhof 24fdd588fd
Code styling tweaks to the tests - Part 1 (#86192) 2023-01-20 13:52:46 +01:00
Franck Nijhof 79b52a2b41
Stricter pylint message control (#86154) 2023-01-20 13:47:55 +01:00
Franck Nijhof 4c2b20db68
Collection of typing improvements in common test helpers (#85509)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2023-01-13 15:12:11 +01:00
J. Nick Koston d81febd3f4
Small speed up to frequently called datetime functions (#85399) 2023-01-08 09:42:29 -10:00
Erik Montnemery 6490dcf099
Import mqtt and recorder locally in test fixtures (#85067) 2023-01-03 20:18:36 +01:00
Joakim Plate 5c43f0861f
Avoid running final writes in executor in test (#84679) 2022-12-28 23:40:11 +01:00
Erik Montnemery 3884e16b46
Add tests.common.ANY (#84240) 2022-12-20 08:20:42 +01:00
Erik Montnemery 8e617bbc1d
Add translation_key property to entites (#82701)
* Add translation_key attribute to entity state

* Update accuweather test

* Index entity translation keys by platform

* Store translation key in entity registry
2022-12-01 09:34:09 +01:00
puddly 8c8994352d
Allow only specific packages to be skipped during startup dependency installation (#82758) 2022-11-30 08:38:52 +01: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
Erik Montnemery e1338adf1a
Allow configuring country and language in core config (#81734)
* Allow configuring country and language in core config

* Add script for updating list of countries

* Use black for formatting

* Fix quoting

* Move country codes to a separate file

* Address review comments

* Add generated/countries.py

* Get default language from owner account

* Remove unused variable

* Add script to generate list of supported languages

* Add tests

* Fix stale docsring

* Use format_python_namespace

* Correct async_user_store

* Improve typing

* Fix with_store decorator

* Initialize language in core store migration

* Fix startup

* Tweak

* Apply suggestions from code review

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

* Update storage.py

Co-authored-by: Franck Nijhof <git@frenck.dev>
2022-11-24 23:25:50 +01:00
J. Nick Koston e4666206ec
Improve time change helper comments (#82349)
* Improve time change helper comments

https://github.com/home-assistant/core/pull/82324#discussion_r1026962806

* Improve time change helper comments

https://github.com/home-assistant/core/pull/82324#discussion_r1026962806
2022-11-19 04:04:19 +01:00
J. Nick Koston 1c6b4967cf
Fix litejet tests (#82324)
Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
2022-11-18 08:19:38 -06:00
J. Nick Koston d0efdd750f
Fix high latency from thundering heard at 0 microseconds (#82233)
* Fix high latency at 0 microseconds

fixes #82231

* fix async_track_utc_time_change alignment

* use replace to preserve fold

* naming

* tweak

* make async_fire_time_changed aware of the thundering heard issue
2022-11-17 14:22:06 -05:00
Erik Montnemery f4951a4f31
Add CI job which runs recorder tests on MariaDB (#80586)
Co-authored-by: Franck Nijhof <git@frenck.dev>
2022-10-19 13:04:28 +02:00
Erik Montnemery 416aad32cc
Don't mock out migration in recorder tests (#80480) 2022-10-17 22:17:08 +02:00
Franck Nijhof e3af2cb6b8
Add some typing to common test helpers (#80337) 2022-10-14 18:23:49 +02:00
Jan Bouwhuis 1f410e884a
Make hass.data["mqtt"] an instance of a DataClass (#77972)
* Use dataclass to reference hass.data globals

* Add discovery_registry_hooks to dataclass

* Move discovery registry hooks to dataclass

* Add device triggers to dataclass

* Cleanup DEVICE_TRIGGERS const

* Add last_discovery to data_class

* Simplify typing for class `Subscription`

* Follow up on comment

* Redo suggested typing change to sasisfy mypy

* Restore typing

* Add mypy version to CI check logging

* revert changes to ci.yaml

* Add docstr for protocol

Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>

* Mypy update after merging #78399

* Remove mypy ignore

* Correct return type

Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
2022-09-17 21:43:42 +02:00
Erik Montnemery 56278a4421
Simplify device registry (#77715)
* Simplify device registry

* Fix test fixture

* Update homeassistant/helpers/device_registry.py

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

* Update device_registry.py

* Remove dead code

Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
2022-09-03 12:50:55 +02:00
Erik Montnemery dfed3ba75e
Move issue_registry to homeassistant.helpers (#77299)
* Move issue_registry to homeassistant.helpers

* Add backwards compatibility
2022-08-25 11:32:06 +02:00
Erik Montnemery fd6ffef52f
Support non-live database migration (#72433)
* Support non-live database migration

* Tweak startup order, add test

* Address review comments

* Fix typo

* Clarify comment about promoting dependencies

* Tweak

* Fix merge mistake

* Fix some tests

* Fix additional test

* Fix additional test

* Adjust tests

* Improve test coverage
2022-07-22 15:11:34 +02:00