Use init_subclass for Config Entries (#26059)
* Use init_subclass for Config Entries * Ignore type
This commit is contained in:
parent
33c35a6c3c
commit
cf2d927f14
4 changed files with 26 additions and 21 deletions
|
@ -44,8 +44,7 @@ def _find_username_from_config(hass, filename):
|
|||
return None
|
||||
|
||||
|
||||
@config_entries.HANDLERS.register(DOMAIN)
|
||||
class HueFlowHandler(config_entries.ConfigFlow):
|
||||
class HueFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
"""Handle a Hue config flow."""
|
||||
|
||||
VERSION = 1
|
||||
|
|
|
@ -17,8 +17,7 @@ def configured_instances(hass):
|
|||
)
|
||||
|
||||
|
||||
@config_entries.HANDLERS.register(DOMAIN)
|
||||
class MetFlowHandler(config_entries.ConfigFlow):
|
||||
class MetFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
"""Config flow for Met component."""
|
||||
|
||||
VERSION = 1
|
||||
|
|
|
@ -670,6 +670,12 @@ async def _old_conf_migrator(old_config):
|
|||
class ConfigFlow(data_entry_flow.FlowHandler):
|
||||
"""Base class for config flows with some helpers."""
|
||||
|
||||
def __init_subclass__(cls, domain=None, **kwargs):
|
||||
"""Initialize a subclass, register if possible."""
|
||||
super().__init_subclass__(**kwargs) # type: ignore
|
||||
if domain is not None:
|
||||
HANDLERS.register(domain)(cls)
|
||||
|
||||
CONNECTION_CLASS = CONN_CLASS_UNKNOWN
|
||||
|
||||
@staticmethod
|
||||
|
|
|
@ -521,31 +521,32 @@ async def test_discovery_notification(hass):
|
|||
mock_entity_platform(hass, "config_flow.test", None)
|
||||
await async_setup_component(hass, "persistent_notification", {})
|
||||
|
||||
class TestFlow(config_entries.ConfigFlow):
|
||||
VERSION = 5
|
||||
with patch.dict(config_entries.HANDLERS):
|
||||
|
||||
async def async_step_discovery(self, user_input=None):
|
||||
if user_input is not None:
|
||||
return self.async_create_entry(
|
||||
title="Test Title", data={"token": "abcd"}
|
||||
)
|
||||
return self.async_show_form(step_id="discovery")
|
||||
class TestFlow(config_entries.ConfigFlow, domain="test"):
|
||||
VERSION = 5
|
||||
|
||||
async def async_step_discovery(self, user_input=None):
|
||||
if user_input is not None:
|
||||
return self.async_create_entry(
|
||||
title="Test Title", data={"token": "abcd"}
|
||||
)
|
||||
return self.async_show_form(step_id="discovery")
|
||||
|
||||
with patch.dict(config_entries.HANDLERS, {"test": TestFlow}):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
"test", context={"source": config_entries.SOURCE_DISCOVERY}
|
||||
)
|
||||
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get("persistent_notification.config_entry_discovery")
|
||||
assert state is not None
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get("persistent_notification.config_entry_discovery")
|
||||
assert state is not None
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(result["flow_id"], {})
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||
result = await hass.config_entries.flow.async_configure(result["flow_id"], {})
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||
|
||||
await hass.async_block_till_done()
|
||||
state = hass.states.get("persistent_notification.config_entry_discovery")
|
||||
assert state is None
|
||||
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):
|
||||
|
|
Loading…
Add table
Reference in a new issue