mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 23:27:37 +00:00
Show the name of the domain in HomeKit when selecting to include (#53169)
This commit is contained in:
parent
eeb01e638a
commit
f24576b08d
@ -1,4 +1,7 @@
|
|||||||
"""Config flow for HomeKit integration."""
|
"""Config flow for HomeKit integration."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import asyncio
|
||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
import string
|
import string
|
||||||
@ -18,7 +21,7 @@ from homeassistant.const import (
|
|||||||
CONF_NAME,
|
CONF_NAME,
|
||||||
CONF_PORT,
|
CONF_PORT,
|
||||||
)
|
)
|
||||||
from homeassistant.core import callback, split_entity_id
|
from homeassistant.core import HomeAssistant, callback, split_entity_id
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.entityfilter import (
|
from homeassistant.helpers.entityfilter import (
|
||||||
CONF_EXCLUDE_DOMAINS,
|
CONF_EXCLUDE_DOMAINS,
|
||||||
@ -26,6 +29,7 @@ from homeassistant.helpers.entityfilter import (
|
|||||||
CONF_INCLUDE_DOMAINS,
|
CONF_INCLUDE_DOMAINS,
|
||||||
CONF_INCLUDE_ENTITIES,
|
CONF_INCLUDE_ENTITIES,
|
||||||
)
|
)
|
||||||
|
from homeassistant.loader import async_get_integration
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
CONF_AUTO_START,
|
CONF_AUTO_START,
|
||||||
@ -108,6 +112,21 @@ _EMPTY_ENTITY_FILTER = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async def _async_name_to_type_map(hass: HomeAssistant) -> dict[str, str]:
|
||||||
|
"""Create a mapping of types of devices/entities HomeKit can support."""
|
||||||
|
integrations = await asyncio.gather(
|
||||||
|
*[async_get_integration(hass, domain) for domain in SUPPORTED_DOMAINS],
|
||||||
|
return_exceptions=True,
|
||||||
|
)
|
||||||
|
name_to_type_map = {
|
||||||
|
domain: domain
|
||||||
|
if isinstance(integrations[idx], Exception)
|
||||||
|
else integrations[idx].name
|
||||||
|
for idx, domain in enumerate(SUPPORTED_DOMAINS)
|
||||||
|
}
|
||||||
|
return name_to_type_map
|
||||||
|
|
||||||
|
|
||||||
class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
"""Handle a config flow for HomeKit."""
|
"""Handle a config flow for HomeKit."""
|
||||||
|
|
||||||
@ -127,13 +146,14 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
self.hk_data[CONF_HOMEKIT_MODE] = HOMEKIT_MODE_BRIDGE
|
self.hk_data[CONF_HOMEKIT_MODE] = HOMEKIT_MODE_BRIDGE
|
||||||
default_domains = [] if self._async_current_names() else DEFAULT_DOMAINS
|
default_domains = [] if self._async_current_names() else DEFAULT_DOMAINS
|
||||||
|
name_to_type_map = await _async_name_to_type_map(self.hass)
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="user",
|
step_id="user",
|
||||||
data_schema=vol.Schema(
|
data_schema=vol.Schema(
|
||||||
{
|
{
|
||||||
vol.Required(
|
vol.Required(
|
||||||
CONF_INCLUDE_DOMAINS, default=default_domains
|
CONF_INCLUDE_DOMAINS, default=default_domains
|
||||||
): cv.multi_select(SUPPORTED_DOMAINS),
|
): cv.multi_select(name_to_type_map),
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@ -437,6 +457,7 @@ class OptionsFlowHandler(config_entries.OptionsFlow):
|
|||||||
include_entities = entity_filter.get(CONF_INCLUDE_ENTITIES)
|
include_entities = entity_filter.get(CONF_INCLUDE_ENTITIES)
|
||||||
if include_entities:
|
if include_entities:
|
||||||
domains.extend(_domains_set_from_entities(include_entities))
|
domains.extend(_domains_set_from_entities(include_entities))
|
||||||
|
name_to_type_map = await _async_name_to_type_map(self.hass)
|
||||||
|
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="init",
|
step_id="init",
|
||||||
@ -448,7 +469,7 @@ class OptionsFlowHandler(config_entries.OptionsFlow):
|
|||||||
vol.Required(
|
vol.Required(
|
||||||
CONF_DOMAINS,
|
CONF_DOMAINS,
|
||||||
default=domains,
|
default=domains,
|
||||||
): cv.multi_select(SUPPORTED_DOMAINS),
|
): cv.multi_select(name_to_type_map),
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user