Use debouncer in mysensors (#84638)

* Use debouncer in mysensors

* Clean cover tests

* Fix debouncer mocking

* Follow typing
This commit is contained in:
Martin Hjelmare 2022-12-27 21:37:10 +01:00 committed by GitHub
parent 624c93bb38
commit d441fb2ec5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 31 additions and 159 deletions

View file

@ -144,8 +144,26 @@ async def integration_fixture(
"""Set up the mysensors integration with a config entry."""
config: dict[str, Any] = {}
config_entry.add_to_hass(hass)
with patch(
"homeassistant.components.mysensors.device.Debouncer", autospec=True
) as debouncer_class:
def debouncer(
*args: Any, function: Callable | None = None, **kwargs: Any
) -> MagicMock:
"""Mock the debouncer."""
async def call_debouncer():
"""Mock call to debouncer."""
if function is not None:
function()
debounce_instance = MagicMock()
debounce_instance.async_call.side_effect = call_debouncer
return debounce_instance
debouncer_class.side_effect = debouncer
with patch("homeassistant.components.mysensors.device.UPDATE_DELAY", new=0):
await async_setup_component(hass, DOMAIN, config)
await hass.async_block_till_done()
yield config_entry