Compare commits
1 commit
dev
...
conversati
Author | SHA1 | Date | |
---|---|---|---|
|
1f1353205f |
5 changed files with 21 additions and 9 deletions
|
@ -545,19 +545,13 @@ async def async_matching_config_entries(
|
||||||
@callback
|
@callback
|
||||||
def entry_json(entry: config_entries.ConfigEntry) -> dict:
|
def entry_json(entry: config_entries.ConfigEntry) -> dict:
|
||||||
"""Return JSON value of a config entry."""
|
"""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 {
|
return {
|
||||||
"entry_id": entry.entry_id,
|
"entry_id": entry.entry_id,
|
||||||
"domain": entry.domain,
|
"domain": entry.domain,
|
||||||
"title": entry.title,
|
"title": entry.title,
|
||||||
"source": entry.source,
|
"source": entry.source,
|
||||||
"state": entry.state.value,
|
"state": entry.state.value,
|
||||||
"supports_options": supports_options,
|
"supports_options": entry.supports_options_flow(),
|
||||||
"supports_remove_device": entry.supports_remove_device or False,
|
"supports_remove_device": entry.supports_remove_device or False,
|
||||||
"supports_unload": entry.supports_unload or False,
|
"supports_unload": entry.supports_unload or False,
|
||||||
"pref_disable_new_entities": entry.pref_disable_new_entities,
|
"pref_disable_new_entities": entry.pref_disable_new_entities,
|
||||||
|
|
|
@ -335,6 +335,7 @@ class AgentInfo:
|
||||||
|
|
||||||
id: str
|
id: str
|
||||||
name: str
|
name: str
|
||||||
|
has_options_flow: bool
|
||||||
|
|
||||||
|
|
||||||
@core.callback
|
@core.callback
|
||||||
|
@ -433,6 +434,7 @@ class AgentManager:
|
||||||
AgentInfo(
|
AgentInfo(
|
||||||
id=HOME_ASSISTANT_AGENT,
|
id=HOME_ASSISTANT_AGENT,
|
||||||
name="Home Assistant",
|
name="Home Assistant",
|
||||||
|
has_options_flow=False,
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
for agent_id, agent in self._agents.items():
|
for agent_id, agent in self._agents.items():
|
||||||
|
@ -451,6 +453,7 @@ class AgentManager:
|
||||||
AgentInfo(
|
AgentInfo(
|
||||||
id=agent_id,
|
id=agent_id,
|
||||||
name=config_entry.title or config_entry.domain,
|
name=config_entry.title or config_entry.domain,
|
||||||
|
has_options_flow=config_entry.supports_options_flow(),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return agents
|
return agents
|
||||||
|
|
|
@ -661,6 +661,12 @@ class ConfigEntry:
|
||||||
|
|
||||||
return lambda: self.update_listeners.remove(weak_listener)
|
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]:
|
def as_dict(self) -> dict[str, Any]:
|
||||||
"""Return dictionary version of this entry."""
|
"""Return dictionary version of this entry."""
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -1,24 +1,28 @@
|
||||||
# serializer version: 1
|
# serializer version: 1
|
||||||
# name: test_get_agent_info
|
# name: test_get_agent_info
|
||||||
dict({
|
dict({
|
||||||
|
'has_options_flow': False,
|
||||||
'id': 'mock-entry',
|
'id': 'mock-entry',
|
||||||
'name': 'Mock Title',
|
'name': 'Mock Title',
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
# name: test_get_agent_info.1
|
# name: test_get_agent_info.1
|
||||||
dict({
|
dict({
|
||||||
|
'has_options_flow': False,
|
||||||
'id': 'homeassistant',
|
'id': 'homeassistant',
|
||||||
'name': 'Home Assistant',
|
'name': 'Home Assistant',
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
# name: test_get_agent_info.2
|
# name: test_get_agent_info.2
|
||||||
dict({
|
dict({
|
||||||
|
'has_options_flow': False,
|
||||||
'id': 'mock-entry',
|
'id': 'mock-entry',
|
||||||
'name': 'Mock Title',
|
'name': 'Mock Title',
|
||||||
})
|
})
|
||||||
# ---
|
# ---
|
||||||
# name: test_get_agent_info.3
|
# name: test_get_agent_info.3
|
||||||
dict({
|
dict({
|
||||||
|
'has_options_flow': False,
|
||||||
'id': 'mock-entry',
|
'id': 'mock-entry',
|
||||||
'name': 'test',
|
'name': 'test',
|
||||||
})
|
})
|
||||||
|
|
|
@ -1110,7 +1110,9 @@ async def test_entry_options(
|
||||||
entry = MockConfigEntry(domain="test", data={"first": True}, options=None)
|
entry = MockConfigEntry(domain="test", data={"first": True}, options=None)
|
||||||
entry.add_to_manager(manager)
|
entry.add_to_manager(manager)
|
||||||
|
|
||||||
class TestFlow:
|
assert entry.supports_options_flow() is False
|
||||||
|
|
||||||
|
class TestFlow(config_entries.ConfigFlow):
|
||||||
"""Test flow."""
|
"""Test flow."""
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -1123,7 +1125,10 @@ async def test_entry_options(
|
||||||
|
|
||||||
return OptionsFlowHandler()
|
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(
|
flow = await manager.options.async_create_flow(
|
||||||
entry.entry_id, context={"source": "test"}, data=None
|
entry.entry_id, context={"source": "test"}, data=None
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue