Migrate matrix to use run_immediately for start listener (#115167)
* Migrate matrix to use run_immediately for start listener * Migrate matrix to use run_immediately for start listener
This commit is contained in:
parent
af1023074e
commit
1fd5f64dcc
3 changed files with 29 additions and 4 deletions
|
@ -220,7 +220,7 @@ class MatrixBot:
|
|||
) # milliseconds.
|
||||
|
||||
self.hass.bus.async_listen_once(
|
||||
EVENT_HOMEASSISTANT_START, handle_startup, run_immediately=False
|
||||
EVENT_HOMEASSISTANT_START, handle_startup, run_immediately=True
|
||||
)
|
||||
|
||||
def _load_commands(self, commands: list[ConfigCommand]) -> None:
|
||||
|
|
|
@ -281,6 +281,9 @@ async def matrix_bot(
|
|||
assert await async_setup_component(hass, MATRIX_DOMAIN, MOCK_CONFIG_DATA)
|
||||
assert await async_setup_component(hass, NOTIFY_DOMAIN, MOCK_CONFIG_DATA)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
# Accessing hass.data in tests is not desirable, but all the tests here
|
||||
# currently do this.
|
||||
assert isinstance(matrix_bot := hass.data[MATRIX_DOMAIN], MatrixBot)
|
||||
|
||||
await hass.async_start()
|
||||
|
|
|
@ -1,14 +1,36 @@
|
|||
"""Test MatrixBot._join."""
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.matrix import MatrixBot
|
||||
from homeassistant.components.matrix.const import DOMAIN as MATRIX_DOMAIN
|
||||
from homeassistant.components.notify import DOMAIN as NOTIFY_DOMAIN
|
||||
from homeassistant.const import EVENT_HOMEASSISTANT_START
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from .conftest import MOCK_CONFIG_DATA
|
||||
|
||||
from tests.components.matrix.conftest import TEST_BAD_ROOM, TEST_JOINABLE_ROOMS
|
||||
|
||||
|
||||
async def test_join(hass, matrix_bot: MatrixBot, caplog):
|
||||
async def test_join(
|
||||
hass: HomeAssistant,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
mock_client,
|
||||
mock_save_json,
|
||||
mock_allowed_path,
|
||||
) -> None:
|
||||
"""Test joining configured rooms."""
|
||||
assert await async_setup_component(hass, MATRIX_DOMAIN, MOCK_CONFIG_DATA)
|
||||
assert await async_setup_component(hass, NOTIFY_DOMAIN, MOCK_CONFIG_DATA)
|
||||
hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
|
||||
await hass.async_block_till_done(wait_background_tasks=True)
|
||||
|
||||
# Accessing hass.data in tests is not desirable, but all the tests here
|
||||
# currently do this.
|
||||
matrix_bot = hass.data[MATRIX_DOMAIN]
|
||||
|
||||
await hass.async_start()
|
||||
for room_id in TEST_JOINABLE_ROOMS:
|
||||
assert f"Joined or already in room '{room_id}'" in caplog.messages
|
||||
|
||||
|
@ -21,7 +43,7 @@ async def test_join(hass, matrix_bot: MatrixBot, caplog):
|
|||
)
|
||||
|
||||
|
||||
async def test_resolve_aliases(hass, matrix_bot: MatrixBot):
|
||||
async def test_resolve_aliases(hass: HomeAssistant, matrix_bot: MatrixBot) -> None:
|
||||
"""Test resolving configured room aliases into room ids."""
|
||||
|
||||
await hass.async_start()
|
||||
|
|
Loading…
Add table
Reference in a new issue