Do not wait for mqtt at startup mqtt_statestream (#91721)

This commit is contained in:
Jan Bouwhuis 2023-04-21 09:00:48 +02:00 committed by GitHub
parent da26b0a930
commit 0552ec834d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 11 deletions

View file

@ -41,15 +41,6 @@ _LOGGER = logging.getLogger(__name__)
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the MQTT state feed."""
# Make sure MQTT is available and the entry is loaded
if not hass.config_entries.async_entries(
mqtt.DOMAIN
) or not await hass.config_entries.async_wait_component(
hass.config_entries.async_entries(mqtt.DOMAIN)[0]
):
_LOGGER.error("MQTT integration is not available")
return False
conf: ConfigType = config[DOMAIN]
publish_filter = convert_include_exclude_filter(conf)
base_topic: str = conf[CONF_BASE_TOPIC]

View file

@ -96,12 +96,19 @@ async def test_setup_and_stop_waits_for_ha(
mqtt_mock.async_publish.assert_not_called()
@pytest.mark.xfail()
async def test_startup_no_mqtt(
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
) -> None:
"""Test startup without MQTT support."""
assert not await add_statestream(hass, base_topic="pub")
assert "MQTT integration is not available" in caplog.text
e_id = "fake.entity"
assert await add_statestream(hass, base_topic="pub")
# Set a state of an entity
mock_state_change_event(hass, State(e_id, "on"))
await hass.async_block_till_done()
await hass.async_block_till_done()
assert "MQTT is not enabled" in caplog.text
async def test_setup_succeeds_with_attributes(