* Create option flow for Rfxtrx integration (#37982) * Implement config flow for rfxtrx integration (#39299) * Add config flow * Add strings * Add first series of tests * Add tests * Adjust tests according review comments * Adjust strings * Add executor for testing connection * Change ports to dict * Fix pylint issue * Adjust tests * Migrate config entry for rfxtrx integration (#39528) * Add rfxtrx device connection validation when importing (#39582) * Implement import connection validation * Fix binary sensor tests * Move rfxtrx data * Fix cover tests * Fix test init * Fix light tests * Fix sensor tests * Fix switch tests * Refactor rfxtrx test data * Fix strings * Fix check * Rework device string in test code * Add option to delete multiple rfxtrx devices (#39625) * Opt to remove multiple devices * Fix devices key * Add tests (phase 1) * Add tests (phase 2) * Tweak remove devices test * Implement device migration function in rfxtrx option flow (#39694) * Prompt option to replace device * Revert unwanted changes * Add replace device function * WIP replace entities * Remove device/entities and update config entry * Fix styling * Add info * Add test * Fix strings * Refactor building migration map * Allow migration for all device types * Add test to migrate control device * Fixup some names * Fixup entry names in test code * Bump pyRFXtrx to 0.26 and deprecate debug config key (#40679) * Create option flow for Rfxtrx integration (#37982) * Implement config flow for rfxtrx integration (#39299) * Add config flow * Add strings * Add first series of tests * Add tests * Adjust tests according review comments * Adjust strings * Add executor for testing connection * Change ports to dict * Fix pylint issue * Adjust tests * Migrate config entry for rfxtrx integration (#39528) * Add rfxtrx device connection validation when importing (#39582) * Implement import connection validation * Fix binary sensor tests * Move rfxtrx data * Fix cover tests * Fix test init * Fix light tests * Fix sensor tests * Fix switch tests * Refactor rfxtrx test data * Fix strings * Fix check * Rework device string in test code * Add option to delete multiple rfxtrx devices (#39625) * Opt to remove multiple devices * Fix devices key * Add tests (phase 1) * Add tests (phase 2) * Tweak remove devices test * Implement device migration function in rfxtrx option flow (#39694) * Prompt option to replace device * Revert unwanted changes * Add replace device function * WIP replace entities * Remove device/entities and update config entry * Fix styling * Add info * Add test * Fix strings * Refactor building migration map * Allow migration for all device types * Add test to migrate control device * Fixup some names * Fixup entry names in test code * Bump version number * Remove debug key from connect * Remove debug option from config flow * Remove debug from tests * Fix event test * Add cv.deprecated * Fix test * Fix config schema * Add timeout on connection * Rework config schema * Fix schema...again * Prevent creation of duplicate device in rfxtrx option flow (#40656)
76 lines
2.2 KiB
Python
76 lines
2.2 KiB
Python
"""Common test tools."""
|
|
from datetime import timedelta
|
|
|
|
import pytest
|
|
|
|
from homeassistant.components import rfxtrx
|
|
from homeassistant.components.rfxtrx import DOMAIN
|
|
from homeassistant.util.dt import utcnow
|
|
|
|
from tests.async_mock import patch
|
|
from tests.common import MockConfigEntry, async_fire_time_changed
|
|
|
|
|
|
def create_rfx_test_cfg(device="abcd", automatic_add=False, devices=None):
|
|
"""Create rfxtrx config entry data."""
|
|
return {
|
|
"device": device,
|
|
"host": None,
|
|
"port": None,
|
|
"automatic_add": automatic_add,
|
|
"debug": False,
|
|
"devices": devices,
|
|
}
|
|
|
|
|
|
@pytest.fixture(autouse=True, name="rfxtrx")
|
|
async def rfxtrx_fixture(hass):
|
|
"""Fixture that cleans up threads from integration."""
|
|
|
|
with patch("RFXtrx.Connect") as connect, patch("RFXtrx.DummyTransport2"):
|
|
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
|
|
|
|
|
|
@pytest.fixture(name="rfxtrx_automatic")
|
|
async def rfxtrx_automatic_fixture(hass, rfxtrx):
|
|
"""Fixture that starts up with automatic additions."""
|
|
entry_data = create_rfx_test_cfg(automatic_add=True, devices={})
|
|
mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data)
|
|
|
|
mock_entry.add_to_hass(hass)
|
|
|
|
await hass.config_entries.async_setup(mock_entry.entry_id)
|
|
await hass.async_block_till_done()
|
|
await hass.async_start()
|
|
yield rfxtrx
|
|
|
|
|
|
@pytest.fixture
|
|
async def timestep(hass):
|
|
"""Step system time forward."""
|
|
|
|
with patch("homeassistant.core.dt_util.utcnow") as mock_utcnow:
|
|
mock_utcnow.return_value = utcnow()
|
|
|
|
async def delay(seconds):
|
|
"""Trigger delay in system."""
|
|
mock_utcnow.return_value += timedelta(seconds=seconds)
|
|
async_fire_time_changed(hass, mock_utcnow.return_value)
|
|
await hass.async_block_till_done()
|
|
|
|
yield delay
|