Skip to content

Commit

Permalink
Update config_flow.py
Browse files Browse the repository at this point in the history
  • Loading branch information
aunefyren committed Feb 5, 2024
1 parent 1479712 commit f5b44b9
Showing 1 changed file with 11 additions and 23 deletions.
34 changes: 11 additions & 23 deletions custom_components/bluesound_alt/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,28 +60,7 @@ async def validate_input(hass: HomeAssistant, data: dict) -> dict[str, Any]:

_LOGGER.debug("Adding new device.")

result = await async_setup_platform(hass, hosts, True, None)
if result is not True:
# If there is an error, raise an exception to notify HA that there was a
# problem. The UI will also show there was a problem
raise CannotConnect

# If your PyPI package is not built with async, pass your methods
# to the executor:
# await hass.async_add_executor_job(
# your_validate_func, data["username"], data["password"]
# )

# If you cannot connect:
# throw CannotConnect
# If the authentication is wrong:
# InvalidAuth

# Return info that you want to store in the config entry.
# "Title" is what is displayed to the user for this hub device
# It is stored internally in HA as part of the device config.
# See `async_step_user` below for how this is used
return {"title": data[CONF_HOST]}
await async_setup_platform(hass, hosts, True, None)


class ExampleConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
Expand All @@ -107,7 +86,16 @@ async def async_step_user(self, user_input=None):
try:
info = await validate_input(self.hass, user_input)

return self.async_create_entry(title=info["title"], data=user_input)
data = {
CONF_NAME: data[CONF_HOST],
CONF_HOST: data[CONF_NAME],
CONF_PORT: DEFAULT_PORT,
}

return self.async_create_entry(
title="bluesound_alt",
data=data,
)
except CannotConnect:
errors["base"] = "cannot_connect"
except InvalidHost:
Expand Down

0 comments on commit f5b44b9

Please sign in to comment.