Fix hue discovery popping up (#14614)
* Fix hue discovery popping up * Fix result * Fix tests
This commit is contained in:
parent
4fb4838bde
commit
fa9b9105a8
5 changed files with 38 additions and 11 deletions
|
@ -347,6 +347,9 @@ class AuthManager:
|
||||||
|
|
||||||
async def _async_finish_login_flow(self, result):
|
async def _async_finish_login_flow(self, result):
|
||||||
"""Result of a credential login flow."""
|
"""Result of a credential login flow."""
|
||||||
|
if result['type'] != data_entry_flow.RESULT_TYPE_CREATE_ENTRY:
|
||||||
|
return None
|
||||||
|
|
||||||
auth_provider = self._providers[result['handler']]
|
auth_provider = self._providers[result['handler']]
|
||||||
return await auth_provider.async_get_or_create_credentials(
|
return await auth_provider.async_get_or_create_credentials(
|
||||||
result['data'])
|
result['data'])
|
||||||
|
|
|
@ -347,6 +347,15 @@ class ConfigEntries:
|
||||||
|
|
||||||
async def _async_finish_flow(self, result):
|
async def _async_finish_flow(self, result):
|
||||||
"""Finish a config flow and add an entry."""
|
"""Finish a config flow and add an entry."""
|
||||||
|
# If no discovery config entries in progress, remove notification.
|
||||||
|
if not any(ent['source'] in DISCOVERY_SOURCES for ent
|
||||||
|
in self.hass.config_entries.flow.async_progress()):
|
||||||
|
self.hass.components.persistent_notification.async_dismiss(
|
||||||
|
DISCOVERY_NOTIFICATION_ID)
|
||||||
|
|
||||||
|
if result['type'] != data_entry_flow.RESULT_TYPE_CREATE_ENTRY:
|
||||||
|
return None
|
||||||
|
|
||||||
entry = ConfigEntry(
|
entry = ConfigEntry(
|
||||||
version=result['version'],
|
version=result['version'],
|
||||||
domain=result['handler'],
|
domain=result['handler'],
|
||||||
|
@ -370,12 +379,6 @@ class ConfigEntries:
|
||||||
if result['source'] not in DISCOVERY_SOURCES:
|
if result['source'] not in DISCOVERY_SOURCES:
|
||||||
return entry
|
return entry
|
||||||
|
|
||||||
# If no discovery config entries in progress, remove notification.
|
|
||||||
if not any(ent['source'] in DISCOVERY_SOURCES for ent
|
|
||||||
in self.hass.config_entries.flow.async_progress()):
|
|
||||||
self.hass.components.persistent_notification.async_dismiss(
|
|
||||||
DISCOVERY_NOTIFICATION_ID)
|
|
||||||
|
|
||||||
return entry
|
return entry
|
||||||
|
|
||||||
async def _async_create_flow(self, handler, *, source, data):
|
async def _async_create_flow(self, handler, *, source, data):
|
||||||
|
|
|
@ -110,11 +110,11 @@ class FlowManager:
|
||||||
# Abort and Success results both finish the flow
|
# Abort and Success results both finish the flow
|
||||||
self._progress.pop(flow.flow_id)
|
self._progress.pop(flow.flow_id)
|
||||||
|
|
||||||
if result['type'] == RESULT_TYPE_ABORT:
|
|
||||||
return result
|
|
||||||
|
|
||||||
# We pass a copy of the result because we're mutating our version
|
# We pass a copy of the result because we're mutating our version
|
||||||
result['result'] = await self._async_finish_flow(dict(result))
|
entry = await self._async_finish_flow(dict(result))
|
||||||
|
|
||||||
|
if result['type'] == RESULT_TYPE_CREATE_ENTRY:
|
||||||
|
result['result'] = entry
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -284,3 +284,23 @@ async def test_discovery_notification(hass):
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
state = hass.states.get('persistent_notification.config_entry_discovery')
|
state = hass.states.get('persistent_notification.config_entry_discovery')
|
||||||
assert state is None
|
assert state is None
|
||||||
|
|
||||||
|
|
||||||
|
async def test_discovery_notification_not_created(hass):
|
||||||
|
"""Test that we not create a notification when discovery is aborted."""
|
||||||
|
loader.set_component(hass, 'test', MockModule('test'))
|
||||||
|
await async_setup_component(hass, 'persistent_notification', {})
|
||||||
|
|
||||||
|
class TestFlow(data_entry_flow.FlowHandler):
|
||||||
|
VERSION = 5
|
||||||
|
|
||||||
|
async def async_step_discovery(self, user_input=None):
|
||||||
|
return self.async_abort(reason='test')
|
||||||
|
|
||||||
|
with patch.dict(config_entries.HANDLERS, {'test': TestFlow}):
|
||||||
|
await hass.config_entries.flow.async_init(
|
||||||
|
'test', source=data_entry_flow.SOURCE_DISCOVERY)
|
||||||
|
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
state = hass.states.get('persistent_notification.config_entry_discovery')
|
||||||
|
assert state is None
|
||||||
|
|
|
@ -21,7 +21,8 @@ def manager():
|
||||||
return handler()
|
return handler()
|
||||||
|
|
||||||
async def async_add_entry(result):
|
async def async_add_entry(result):
|
||||||
entries.append(result)
|
if (result['type'] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY):
|
||||||
|
entries.append(result)
|
||||||
|
|
||||||
manager = data_entry_flow.FlowManager(
|
manager = data_entry_flow.FlowManager(
|
||||||
None, async_create_flow, async_add_entry)
|
None, async_create_flow, async_add_entry)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue