Avoid using implementation internal to trigger events (#38041)

This uses the moxking in fixture to trigger events.
This commit is contained in:
Joakim Plate authored and GitHub committed 2020-07-22 00:24:26 +02:00
1 parent 945acb4e29
commit 7a3c6d6525
8 files changed
+41 -50

No files matched your search

+18 -2
View File
@@ -3,10 +3,26 @@ from unittest import mock
import pytest
from homeassistant.components import rfxtrx
@pytest.fixture(autouse=True, name="rfxtrx")
async def rfxtrx(hass):
async def rfxtrx_fixture(hass):
"""Fixture that cleans up threads from integration."""
with mock.patch("RFXtrx.Connect") as connect, mock.patch("RFXtrx.DummyTransport2"):
yield connect.return_value
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