mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Use init_subclass for Config Entries (#26059)
* Use init_subclass for Config Entries * Ignore type
This commit is contained in:
parent
33c35a6c3c
commit
cf2d927f14
@ -44,8 +44,7 @@ def _find_username_from_config(hass, filename):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
@config_entries.HANDLERS.register(DOMAIN)
|
class HueFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
class HueFlowHandler(config_entries.ConfigFlow):
|
|
||||||
"""Handle a Hue config flow."""
|
"""Handle a Hue config flow."""
|
||||||
|
|
||||||
VERSION = 1
|
VERSION = 1
|
||||||
|
@ -17,8 +17,7 @@ def configured_instances(hass):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@config_entries.HANDLERS.register(DOMAIN)
|
class MetFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
class MetFlowHandler(config_entries.ConfigFlow):
|
|
||||||
"""Config flow for Met component."""
|
"""Config flow for Met component."""
|
||||||
|
|
||||||
VERSION = 1
|
VERSION = 1
|
||||||
|
@ -670,6 +670,12 @@ async def _old_conf_migrator(old_config):
|
|||||||
class ConfigFlow(data_entry_flow.FlowHandler):
|
class ConfigFlow(data_entry_flow.FlowHandler):
|
||||||
"""Base class for config flows with some helpers."""
|
"""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
|
CONNECTION_CLASS = CONN_CLASS_UNKNOWN
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -521,7 +521,9 @@ async def test_discovery_notification(hass):
|
|||||||
mock_entity_platform(hass, "config_flow.test", None)
|
mock_entity_platform(hass, "config_flow.test", None)
|
||||||
await async_setup_component(hass, "persistent_notification", {})
|
await async_setup_component(hass, "persistent_notification", {})
|
||||||
|
|
||||||
class TestFlow(config_entries.ConfigFlow):
|
with patch.dict(config_entries.HANDLERS):
|
||||||
|
|
||||||
|
class TestFlow(config_entries.ConfigFlow, domain="test"):
|
||||||
VERSION = 5
|
VERSION = 5
|
||||||
|
|
||||||
async def async_step_discovery(self, user_input=None):
|
async def async_step_discovery(self, user_input=None):
|
||||||
@ -531,7 +533,6 @@ async def test_discovery_notification(hass):
|
|||||||
)
|
)
|
||||||
return self.async_show_form(step_id="discovery")
|
return self.async_show_form(step_id="discovery")
|
||||||
|
|
||||||
with patch.dict(config_entries.HANDLERS, {"test": TestFlow}):
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
"test", context={"source": config_entries.SOURCE_DISCOVERY}
|
"test", context={"source": config_entries.SOURCE_DISCOVERY}
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user