mirror of
https://github.com/home-assistant/core.git
synced 2026-08-24 10:13:52 -05:00
72 lines
2.2 KiB
Python
72 lines
2.2 KiB
Python
"""Config flow for Marantz IR integration."""
|
|
|
|
from typing import Any, override
|
|
|
|
import voluptuous as vol
|
|
|
|
from homeassistant.components.infrared import (
|
|
DOMAIN as INFRARED_DOMAIN,
|
|
async_get_emitters,
|
|
)
|
|
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
|
|
from homeassistant.const import CONF_MODEL
|
|
from homeassistant.helpers.selector import (
|
|
EntitySelector,
|
|
EntitySelectorConfig,
|
|
SelectOptionDict,
|
|
SelectSelector,
|
|
SelectSelectorConfig,
|
|
SelectSelectorMode,
|
|
)
|
|
|
|
from .const import CONF_INFRARED_EMITTER_ENTITY_ID, DOMAIN, MODELS
|
|
|
|
|
|
class MarantzIrConfigFlow(ConfigFlow, domain=DOMAIN):
|
|
"""Handle config flow for Marantz IR."""
|
|
|
|
VERSION = 1
|
|
|
|
@override
|
|
async def async_step_user(
|
|
self, user_input: dict[str, Any] | None = None
|
|
) -> ConfigFlowResult:
|
|
"""Handle the initial step."""
|
|
emitter_entity_ids = async_get_emitters(self.hass)
|
|
if not emitter_entity_ids:
|
|
return self.async_abort(reason="no_emitters")
|
|
|
|
if user_input is not None:
|
|
entity_id = user_input[CONF_INFRARED_EMITTER_ENTITY_ID]
|
|
model = user_input[CONF_MODEL]
|
|
|
|
await self.async_set_unique_id(f"{model}_{entity_id}")
|
|
self._abort_if_unique_id_configured()
|
|
|
|
return self.async_create_entry(title=MODELS[model].name, data=user_input)
|
|
|
|
model_options = [
|
|
SelectOptionDict(value=slug, label=model.name)
|
|
for slug, model in MODELS.items()
|
|
]
|
|
|
|
return self.async_show_form(
|
|
step_id="user",
|
|
data_schema=vol.Schema(
|
|
{
|
|
vol.Required(CONF_MODEL): SelectSelector(
|
|
SelectSelectorConfig(
|
|
options=model_options,
|
|
mode=SelectSelectorMode.DROPDOWN,
|
|
)
|
|
),
|
|
vol.Required(CONF_INFRARED_EMITTER_ENTITY_ID): EntitySelector(
|
|
EntitySelectorConfig(
|
|
domain=INFRARED_DOMAIN,
|
|
include_entities=emitter_entity_ids,
|
|
)
|
|
),
|
|
}
|
|
),
|
|
)
|