mirror of
https://github.com/home-assistant/core.git
synced 2025-12-25 05:26:47 +00:00
Update Hue data fetching (#31338)
* Refactor Hue Lights to use DataCoordinator * Redo how Hue updates data * Address comments * Inherit from Entity and remove pylint disable * Add tests for debounce
This commit is contained in:
62
tests/helpers/test_debounce.py
Normal file
62
tests/helpers/test_debounce.py
Normal file
@@ -0,0 +1,62 @@
|
||||
"""Tests for debounce."""
|
||||
from asynctest import CoroutineMock
|
||||
|
||||
from homeassistant.helpers import debounce
|
||||
|
||||
|
||||
async def test_immediate_works(hass):
|
||||
"""Test immediate works."""
|
||||
calls = []
|
||||
debouncer = debounce.Debouncer(
|
||||
hass, None, 0.01, True, CoroutineMock(side_effect=lambda: calls.append(None))
|
||||
)
|
||||
|
||||
await debouncer.async_call()
|
||||
assert len(calls) == 1
|
||||
assert debouncer._timer_task is not None
|
||||
assert debouncer._execute_at_end_of_timer is False
|
||||
|
||||
await debouncer.async_call()
|
||||
assert len(calls) == 1
|
||||
assert debouncer._timer_task is not None
|
||||
assert debouncer._execute_at_end_of_timer is True
|
||||
|
||||
debouncer.async_cancel()
|
||||
assert debouncer._timer_task is None
|
||||
assert debouncer._execute_at_end_of_timer is False
|
||||
|
||||
await debouncer.async_call()
|
||||
assert len(calls) == 2
|
||||
await debouncer._handle_timer_finish()
|
||||
assert len(calls) == 2
|
||||
assert debouncer._timer_task is None
|
||||
assert debouncer._execute_at_end_of_timer is False
|
||||
|
||||
|
||||
async def test_not_immediate_works(hass):
|
||||
"""Test immediate works."""
|
||||
calls = []
|
||||
debouncer = debounce.Debouncer(
|
||||
hass, None, 0.01, False, CoroutineMock(side_effect=lambda: calls.append(None))
|
||||
)
|
||||
|
||||
await debouncer.async_call()
|
||||
assert len(calls) == 0
|
||||
assert debouncer._timer_task is not None
|
||||
assert debouncer._execute_at_end_of_timer is True
|
||||
|
||||
await debouncer.async_call()
|
||||
assert len(calls) == 0
|
||||
assert debouncer._timer_task is not None
|
||||
assert debouncer._execute_at_end_of_timer is True
|
||||
|
||||
debouncer.async_cancel()
|
||||
assert debouncer._timer_task is None
|
||||
assert debouncer._execute_at_end_of_timer is False
|
||||
|
||||
await debouncer.async_call()
|
||||
assert len(calls) == 0
|
||||
await debouncer._handle_timer_finish()
|
||||
assert len(calls) == 1
|
||||
assert debouncer._timer_task is None
|
||||
assert debouncer._execute_at_end_of_timer is False
|
||||
Reference in New Issue
Block a user