Compare commits

...
Sign in to create a new pull request.

1 commit

Author SHA1 Message Date
Paulus Schoutsen
1f1353205f Conversation API to include if there is an options flow 2023-06-02 15:35:46 -04:00
5 changed files with 21 additions and 9 deletions

View file

@ -545,19 +545,13 @@ async def async_matching_config_entries(
@callback
def entry_json(entry: config_entries.ConfigEntry) -> dict:
"""Return JSON value of a config entry."""
handler = config_entries.HANDLERS.get(entry.domain)
# work out if handler has support for options flow
supports_options = handler is not None and handler.async_supports_options_flow(
entry
)
return {
"entry_id": entry.entry_id,
"domain": entry.domain,
"title": entry.title,
"source": entry.source,
"state": entry.state.value,
"supports_options": supports_options,
"supports_options": entry.supports_options_flow(),
"supports_remove_device": entry.supports_remove_device or False,
"supports_unload": entry.supports_unload or False,
"pref_disable_new_entities": entry.pref_disable_new_entities,

View file

@ -335,6 +335,7 @@ class AgentInfo:
id: str
name: str
has_options_flow: bool
@core.callback
@ -433,6 +434,7 @@ class AgentManager:
AgentInfo(
id=HOME_ASSISTANT_AGENT,
name="Home Assistant",
has_options_flow=False,
)
]
for agent_id, agent in self._agents.items():
@ -451,6 +453,7 @@ class AgentManager:
AgentInfo(
id=agent_id,
name=config_entry.title or config_entry.domain,
has_options_flow=config_entry.supports_options_flow(),
)
)
return agents

View file

@ -661,6 +661,12 @@ class ConfigEntry:
return lambda: self.update_listeners.remove(weak_listener)
def supports_options_flow(self) -> bool:
"""Return if config entry supports options flow."""
return (
handler := HANDLERS.get(self.domain)
) is not None and handler.async_supports_options_flow(self)
def as_dict(self) -> dict[str, Any]:
"""Return dictionary version of this entry."""
return {

View file

@ -1,24 +1,28 @@
# serializer version: 1
# name: test_get_agent_info
dict({
'has_options_flow': False,
'id': 'mock-entry',
'name': 'Mock Title',
})
# ---
# name: test_get_agent_info.1
dict({
'has_options_flow': False,
'id': 'homeassistant',
'name': 'Home Assistant',
})
# ---
# name: test_get_agent_info.2
dict({
'has_options_flow': False,
'id': 'mock-entry',
'name': 'Mock Title',
})
# ---
# name: test_get_agent_info.3
dict({
'has_options_flow': False,
'id': 'mock-entry',
'name': 'test',
})

View file

@ -1110,7 +1110,9 @@ async def test_entry_options(
entry = MockConfigEntry(domain="test", data={"first": True}, options=None)
entry.add_to_manager(manager)
class TestFlow:
assert entry.supports_options_flow() is False
class TestFlow(config_entries.ConfigFlow):
"""Test flow."""
@staticmethod
@ -1123,7 +1125,10 @@ async def test_entry_options(
return OptionsFlowHandler()
config_entries.HANDLERS["test"] = TestFlow()
config_entries.HANDLERS["test"] = TestFlow
assert entry.supports_options_flow() is True
flow = await manager.options.async_create_flow(
entry.entry_id, context={"source": "test"}, data=None
)