Commit Graph

120 Commits (06220849fcf1b59adf9be9ed4b7b52a0280afa43)

Author SHA1 Message Date
J. Nick Koston 7803ca2612
Fix emulated_hue with None values (#104020) 2023-11-15 10:27:50 +01:00
J. Nick Koston 547c38a515
Cache emulated_hue local ip check (#102020) 2023-10-14 16:19:10 -10:00
Ville Skyttä e7b6037419
Remove unnnecessary pylint configs from components [e-l]* (#99004) 2023-08-25 09:46:34 +02:00
Ville Skyttä 3094991236
Upgrade ruff to 0.0.285 (#98647) 2023-08-19 08:17:17 -04:00
Franck Nijhof 3e85a29b86
Move overlapping pylint rules to ruff, disable mypy overlap (#94359) 2023-06-27 17:42:46 +02:00
Erik Montnemery 9a3077d64a
Always setup demo platforms with device support from config entry (#94586)
* Always setup demo platforms with device support from config entry

* Adjust test fixutres

* Update tests depending on the demo integration
2023-06-14 16:50:35 +02:00
Jan Bouwhuis ec98e22330
Add type hints for stub_blueprint_populate fixture (#93568)
Add typehints for stub_blueprint_populate fixture
2023-05-26 08:13:13 +02:00
Erik Montnemery 3cca338c6e
Improve blueprint test fixtures (#93519) 2023-05-25 13:45:19 +02:00
J. Nick Koston e27554f7a6
Improve http handler performance (#93324) 2023-05-21 13:36: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 728f62b1ec
Add type hints to integration tests (part 5) (#87850) 2023-02-12 19:39:48 +01:00
epenet 3052de3e8e
Add type hints to integration tests (d-e) (#87699) 2023-02-08 13:01:44 +01:00
Thomas Hollstegge 589ff54e63
Do not return cached values for entity states in emulated_hue (#87642)
* Do not return cached values for state and brightness

* Move building the uncached state dict behind a lru_cache (_build_entity_state_dict)

---------

Co-authored-by: J. Nick Koston <nick@koston.org>
2023-02-07 13:39:08 -05:00
epenet 4142f0d15d
Add return type to tests without arguments (#87613)
* Add return type to tests without arguments

* Black

* Cancel fixture amends
2023-02-07 14:20:06 +01:00
Gregory Haynes 936ffafd27
Add missing name field to emulated_hue config (#87456)
Co-authored-by: J. Nick Koston <nick@koston.org>
2023-02-05 11:34:37 -06:00
Franck Nijhof c56832bb2c
Enable Ruff SIM300 (#86793) 2023-01-30 11:03:23 +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
Joakim Plate 8bd4125390
Test corrections noticed during pytest upgrade (#82579)
* Withing trigger a call to coordinator after init

* Stop discovery task on STOP event

* Stop dsmr connection task on STOP

* Use autospec in modem_serial tests

close on AioSerial is non async, and should not be mocked as a coroutine

* Make sure responder is specced correctly

tests/components/emulated_hue/test_init.py::test_setup_works
  /Users/joakim/src/hass/home-assistant/homeassistant/components/emulated_hue/__init__.py:119: RuntimeWarning: coroutine 'AsyncMockMixin._execute_mock_call' was never awaited
    protocol.close()

* Don't assume Pymodbus is the only thing logging

* Use gather instead of wait

```
homeassistant/components/homeassistant/__init__.py:208: DeprecationWarning: The explicit passing of coroutine objects to asyncio.wait() is deprecated since Python 3.8, and scheduled for removal in Python 3.11.
```

* Increase wait time for automation tests

Assuming exit within 1 seconds is unreasonable on a potentially loaded
test machine.

* Avoid changing app state after startup
2022-11-23 20:53:28 +01:00
epenet f453726b18
Cleanup HVACAction and HVACMode in tests (#78813) 2022-09-20 20:30:54 +02:00
J. Nick Koston f4d339119f
Cache which entities are exposed in emulated_hue (#73093) 2022-06-09 21:17:37 -10:00
Marc Mueller 62a5854e40
Fix bare except (#72906) 2022-06-02 13:58:04 +02:00
J. Nick Koston 1c334605b6
Enable strict typing to emulated_hue (#72676)
* Add typing to emulated_hue part 2

* cleanups

* adjust targets in test
2022-05-30 08:49:37 +02:00
J. Nick Koston 237ef6419b
Add basic typing to emulated_hue (#72663)
* Add basic typing to emulated_hue

* type a few more places

* fixes

* numbers are always stringified

* numbers are always stringified

* coverage

* drop assert
2022-05-29 18:27:32 +02:00
J. Nick Koston 723dcbafca
Complete fan speed transition from #59781 (#67743) 2022-03-09 10:38:12 +01:00
Paulus Schoutsen 6ef64f6b1c
Fix CORS error in emulated_hue (#59570) 2021-11-11 22:11:41 -08:00
Ville Skyttä 8bc1509afa
Use HTTPStatus instead of HTTP_ consts and magic values in comp.../[de]* (#57990) 2021-10-22 16:28:56 +02:00
Erik Montnemery f6682ba99d
Block tests from opening sockets (#55516) 2021-10-05 14:46:09 -10:00
Simone Chemelli 8b6d0ca13f
Replace util.get_local_ip in favor of components.network.async_get_source_ip() - part 2 (#53368)
Co-authored-by: J. Nick Koston <nick@koston.org>
2021-09-06 08:44:38 -10:00
Erik Montnemery 05abf1405d
Migrate emulated_hue tests from unittest to pytest (#55794)
* Migrate emulated_hue tests from unittest to pytest

* Remove unused variables
2021-09-06 13:24:00 +02:00
Erik Montnemery d5b6dc4f26
Use hass_client_no_auth test fixture in integrations a-g (#55581) 2021-09-02 14:49:20 +02:00
Erik Montnemery 3db21b407a
Add support for color_mode white to demo light (#51575)
* Add support for color_mode white to demo light

* Fix unique_id for newly added light

* Update tests
2021-06-07 20:26:25 +02:00
J. Nick Koston 70961c79a0
Migrate emulate_hue to use storage to fix I/O in event loop (#50473) 2021-05-12 16:10:28 +02:00
Erik Montnemery bf57c77d5c
Add color_mode to demo light (#49694)
* Update demo light with color mode support

* Add rgbw and rgbww color properties

* Update demo light

* Tweak

* Remove unneeded _clear_colors
2021-04-29 10:45:17 +02:00
Franck Nijhof 89e7983ee0
Add Blueprint foundation to Scripts (#48621)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2021-04-27 15:15:38 -07:00
Thomas Hollstegge 66dbb17a4a
Fix opening cover via emulated_hue without specifying a position (#49570) 2021-04-22 19:12:52 -10:00
Erik Montnemery a9065f381d
Use supported_color_modes in emulated_hue (#49175) 2021-04-22 16:42:28 -07:00
Franck Nijhof ad13a9295e
Merge multiple context managers in tests (#48146) 2021-03-27 09:17:15 +01:00
Franck Nijhof 5a2b5fe7c5
Yoda assertion style removed is (#48142) 2021-03-20 13:55:10 +01:00
Dan Klaffenbach 5174f63fd8
Add definitions for grouping media players (#41193)
* Add definitions for grouping media players

See https://github.com/home-assistant/architecture/issues/364

* Fix Google Assistant tests

* Define sync versions of async_join_players/async_unjoin

* Don't use async API in synchronous test methods

* Fix tests and make pylint happy

The method name `unjoin` is used by another component, so let's use
`unjoin_player` instead.

* Fix emulated_hue tests

The new media player entity in the `demo` component requires a tiny
adjustment in the emulated_hue tests.

* Use "target:" in service description

* Also use "name:" in service descriptions

Co-authored-by: Franck Nijhof <git@frenck.dev>
2021-03-18 18:19:28 +01:00
denes44 14d914e300
Enable emulated_hue setting XY color and transition time by client (#45844)
* Enable setting XY color and transition time by client

* New test for setting XY color value

* Correct block outdent

* New test for setting transition time value

* Fixed commented out code
2021-02-03 15:35:27 -10:00
J. Nick Koston 068d1b5eb8
Separate fan speeds into percentages and presets modes (#45407)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
Co-authored-by: John Carr <john.carr@unrouted.co.uk>
2021-01-27 17:44:36 -06:00
Franck Nijhof 65cf2fcb6f
Drop asynctest (#44746) 2021-01-01 22:31:56 +01:00
springstan 6a7caad8dc
Use content type json constant (#40312) 2020-09-23 20:21:55 +02:00
Jean-Yves Avenard cf4b6307ae
Provide compatibility with older Home Assistant installations. (#39539)
Prior 0.113 all lights and switches were reported as dimmable devices and this was fixed by #37978.
However, under some circumstances Alexa will not smoothly transition from those broken devices to the new ones as it cache the list of entities.
It is imperative to have Alexa rediscover all devices and then remove the now non-responding duplicates using the Alexa phone App. This can take quite a while if you have lots of devices.
An alternative would be to log to the Alexa web site and remove all the lights instead and then re-discover them all.

If you have multiple echo devices on your network, it is possible that the entries would continue to show as duplicates. This is due to an individual echo devices caching the old list and re-using it.
The only known solution for this is to remove your echo devices from your Amazon account and re-add them.
After that, have Alexa rediscover all your devices.

This is a one-off requirement.

Fixes #39503
2020-09-01 09:16:40 -05:00
J. Nick Koston 3cc099af80
Make emulated_hue upnp responder async (#39126) 2020-08-23 09:50:59 +02:00
J. Nick Koston 4371068f6a
Fix emulated hue on/off devices compatibility with alexa (#39063) 2020-08-20 10:27:14 +02:00
kbickar 1505343b4b
Update emulated_hue to allow getting bridge config without username (#38986)
* Allow bridge config without username

* Updated emulated_hue tests

* Test cleanup
2020-08-18 14:02:38 -05:00
Franck Nijhof cc4ebc925c
Improve X-Forwarded-* request headers handling (#38696)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
Co-authored-by: Franck Nijhof <git@frenck.dev>
Co-authored-by: Pascal Vizeli <pvizeli@syshack.ch>
2020-08-11 22:57:50 +02:00
Jean-Yves Avenard 988cbf12ce
Cache emulated hue states attributes between get and put calls to avoid unexpected alexa errors (#38451)
* Wait for the state of the entity to actually change before resolving PUT request

Additionally, we cache the entity's properties for up to two seconds for the successive GET state request

When Alexa issues a command to a Hue hub; it immediately queries the hub for the entity's state to confirm if the command was successful.
It expects the state to be effective immediately after the PUT request has been completed.
There may be a delay for the new state to actually be active, this is particularly obvious when using group lights.
This leads Alexa to report that the light had an error.

So we wait for the state of the entity to actually change before responding to the PUT request.

Due to rounding issue when converting the HA range (0..255) to Hue range (1..254) we now cache the state sets by Alexa and return those cached values for up to two seconds so that Alexa gets the same value as it originally set.

Fixes #38446

* Add new tests verifying emulated_hue behaviour.

* Increase code test coverage.

The remaining uncovered lines can't be tested as they mostly check that the hass framework or the http server properly work.

This commit doesn't attempt to fix exposed issues as it would be out of scope ; it merely create the tests to exercise the whole code.

* Update homeassistant/components/emulated_hue/hue_api.py

* Add test for state change wait timeout

* Preserve the cache long enough for groups to change

* Update tests/components/emulated_hue/test_hue_api.py

Co-authored-by: J. Nick Koston <nick@koston.org>
2020-08-03 15:30:16 -10:00