mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Fix hue discovery popping up (#14614)
* Fix hue discovery popping up * Fix result * Fix tests
This commit is contained in:
parent
4fb4838bde
commit
fa9b9105a8
@ -347,6 +347,9 @@ class AuthManager:
|
||||
|
||||
async def _async_finish_login_flow(self, result):
|
||||
"""Result of a credential login flow."""
|
||||
if result['type'] != data_entry_flow.RESULT_TYPE_CREATE_ENTRY:
|
||||
return None
|
||||
|
||||
auth_provider = self._providers[result['handler']]
|
||||
return await auth_provider.async_get_or_create_credentials(
|
||||
result['data'])
|
||||
|
@ -347,6 +347,15 @@ class ConfigEntries:
|
||||
|
||||
async def _async_finish_flow(self, result):
|
||||
"""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(
|
||||
version=result['version'],
|
||||
domain=result['handler'],
|
||||
@ -370,12 +379,6 @@ class ConfigEntries:
|
||||
if result['source'] not in DISCOVERY_SOURCES:
|
||||
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
|
||||
|
||||
async def _async_create_flow(self, handler, *, source, data):
|
||||
|
@ -110,11 +110,11 @@ class FlowManager:
|
||||
# Abort and Success results both finish the flow
|
||||
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
|
||||
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
|
||||
|
||||
|
||||
|
@ -284,3 +284,23 @@ async def test_discovery_notification(hass):
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get('persistent_notification.config_entry_discovery')
|
||||
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,6 +21,7 @@ def manager():
|
||||
return handler()
|
||||
|
||||
async def async_add_entry(result):
|
||||
if (result['type'] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY):
|
||||
entries.append(result)
|
||||
|
||||
manager = data_entry_flow.FlowManager(
|
||||
|
Loading…
x
Reference in New Issue
Block a user