Allow discovery flows to be discovered via zeroconf/ssdp (#24199)

This commit is contained in:
Paulus Schoutsen 2019-05-30 14:08:05 -07:00 committed by GitHub
parent 6fcd56c462
commit f32d1c0dea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 5 deletions

View File

@ -81,6 +81,9 @@ class DiscoveryFlowHandler(config_entries.ConfigFlow):
return await self.async_step_confirm()
async_step_zeroconf = async_step_discovery
async_step_ssdp = async_step_discovery
async def async_step_import(self, _):
"""Handle a flow initialized by import."""
if self._async_in_progress() or self._async_current_entries():

View File

@ -75,24 +75,26 @@ async def test_user_has_confirmation(hass, discovery_flow_conf):
assert result['type'] == data_entry_flow.RESULT_TYPE_FORM
async def test_discovery_single_instance(hass, discovery_flow_conf):
"""Test we ask for confirmation via discovery."""
@pytest.mark.parametrize('source', ['discovery', 'ssdp', 'zeroconf'])
async def test_discovery_single_instance(hass, discovery_flow_conf, source):
"""Test we not allow duplicates."""
flow = config_entries.HANDLERS['test']()
flow.hass = hass
MockConfigEntry(domain='test').add_to_hass(hass)
result = await flow.async_step_discovery({})
result = await getattr(flow, "async_step_{}".format(source))({})
assert result['type'] == data_entry_flow.RESULT_TYPE_ABORT
assert result['reason'] == 'single_instance_allowed'
async def test_discovery_confirmation(hass, discovery_flow_conf):
@pytest.mark.parametrize('source', ['discovery', 'ssdp', 'zeroconf'])
async def test_discovery_confirmation(hass, discovery_flow_conf, source):
"""Test we ask for confirmation via discovery."""
flow = config_entries.HANDLERS['test']()
flow.hass = hass
result = await flow.async_step_discovery({})
result = await getattr(flow, "async_step_{}".format(source))({})
assert result['type'] == data_entry_flow.RESULT_TYPE_FORM
assert result['step_id'] == 'confirm'