2020-07-03 10:22:02 +02:00
|
|
|
"""Common test tools."""
|
|
|
|
from unittest import mock
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
2020-07-22 00:24:26 +02:00
|
|
|
from homeassistant.components import rfxtrx
|
|
|
|
|
2020-07-03 10:22:02 +02:00
|
|
|
|
2020-07-12 22:03:22 +02:00
|
|
|
@pytest.fixture(autouse=True, name="rfxtrx")
|
2020-07-22 00:24:26 +02:00
|
|
|
async def rfxtrx_fixture(hass):
|
2020-07-03 10:22:02 +02:00
|
|
|
"""Fixture that cleans up threads from integration."""
|
|
|
|
|
2020-07-12 22:03:22 +02:00
|
|
|
with mock.patch("RFXtrx.Connect") as connect, mock.patch("RFXtrx.DummyTransport2"):
|
2020-07-22 00:24:26 +02:00
|
|
|
rfx = connect.return_value
|
|
|
|
|
|
|
|
async def _signal_event(packet_id):
|
|
|
|
event = rfxtrx.get_rfx_object(packet_id)
|
|
|
|
await hass.async_add_executor_job(
|
|
|
|
rfx.event_callback, event,
|
|
|
|
)
|
|
|
|
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
return event
|
|
|
|
|
|
|
|
rfx.signal = _signal_event
|
|
|
|
|
|
|
|
yield rfx
|