mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Add Hass.io discovery to MQTT (#16962)
* Add Hass.io discovery to MQTT * Update en.json * Update __init__.py * Update config_flow.py * Update strings.json * Update test_config_flow.py * Lint * Ensure we don't send bad data in config entry
This commit is contained in:
@@ -5,7 +5,7 @@ import pytest
|
||||
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.common import mock_coro
|
||||
from tests.common import mock_coro, MockConfigEntry
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
@@ -88,3 +88,67 @@ async def test_manual_config_set(hass, mock_try_connection,
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
'mqtt', context={'source': 'user'})
|
||||
assert result['type'] == 'abort'
|
||||
|
||||
|
||||
async def test_user_single_instance(hass):
|
||||
"""Test we only allow a single config flow."""
|
||||
MockConfigEntry(domain='mqtt').add_to_hass(hass)
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
'mqtt', context={'source': 'user'})
|
||||
assert result['type'] == 'abort'
|
||||
assert result['reason'] == 'single_instance_allowed'
|
||||
|
||||
|
||||
async def test_hassio_single_instance(hass):
|
||||
"""Test we only allow a single config flow."""
|
||||
MockConfigEntry(domain='mqtt').add_to_hass(hass)
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
'mqtt', context={'source': 'hassio'})
|
||||
assert result['type'] == 'abort'
|
||||
assert result['reason'] == 'single_instance_allowed'
|
||||
|
||||
|
||||
async def test_hassio_confirm(hass, mock_try_connection,
|
||||
mock_finish_setup):
|
||||
"""Test we can finish a config flow."""
|
||||
mock_try_connection.return_value = True
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
'mqtt',
|
||||
data={
|
||||
'addon': 'Mock Addon',
|
||||
'broker': 'mock-broker',
|
||||
'port': 1883,
|
||||
'username': 'mock-user',
|
||||
'password': 'mock-pass',
|
||||
'protocol': '3.1.1'
|
||||
},
|
||||
context={'source': 'hassio'}
|
||||
)
|
||||
assert result['type'] == 'form'
|
||||
assert result['step_id'] == 'hassio_confirm'
|
||||
assert result['description_placeholders'] == {
|
||||
'addon': 'Mock Addon',
|
||||
}
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result['flow_id'], {
|
||||
'discovery': True,
|
||||
}
|
||||
)
|
||||
|
||||
assert result['type'] == 'create_entry'
|
||||
assert result['result'].data == {
|
||||
'broker': 'mock-broker',
|
||||
'port': 1883,
|
||||
'username': 'mock-user',
|
||||
'password': 'mock-pass',
|
||||
'protocol': '3.1.1',
|
||||
'discovery': True,
|
||||
}
|
||||
# Check we tried the connection
|
||||
assert len(mock_try_connection.mock_calls) == 1
|
||||
# Check config entry got setup
|
||||
assert len(mock_finish_setup.mock_calls) == 1
|
||||
|
||||
Reference in New Issue
Block a user