Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add experimental toggle when creating config entry #3164

Merged
merged 1 commit into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 47 additions & 10 deletions custom_components/hacs/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
"""Adds config flow for HACS."""
from __future__ import annotations

from typing import TYPE_CHECKING

from aiogithubapi import GitHubDeviceAPI, GitHubException
from aiogithubapi.common.const import OAUTH_USER_LOGIN
from awesomeversion import AwesomeVersion
Expand All @@ -11,15 +15,29 @@
import voluptuous as vol

from .base import HacsBase
from .const import CLIENT_ID, DOMAIN, MINIMUM_HA_VERSION
from .const import CLIENT_ID, DOMAIN, LOCALE, MINIMUM_HA_VERSION
from .enums import ConfigurationType
from .utils.configuration_schema import RELEASE_LIMIT, hacs_config_option_schema
from .utils.configuration_schema import (
APPDAEMON,
COUNTRY,
DEBUG,
EXPERIMENTAL,
NETDAEMON,
RELEASE_LIMIT,
SIDEPANEL_ICON,
SIDEPANEL_TITLE,
)
from .utils.logger import LOGGER

if TYPE_CHECKING:
from homeassistant.core import HomeAssistant


class HacsFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
"""Config flow for HACS."""

hass: HomeAssistant

VERSION = 1
CONNECTION_CLASS = config_entries.CONN_CLASS_CLOUD_POLL

Expand All @@ -32,6 +50,7 @@ def __init__(self):
self._progress_task = None
self._login_device = None
self._reauth = False
self._user_input = {}

async def async_step_user(self, user_input):
"""Handle a flow initialized by the user."""
Expand All @@ -42,10 +61,12 @@ async def async_step_user(self, user_input):
return self.async_abort(reason="single_instance_allowed")

if user_input:
if [x for x in user_input if not user_input[x]]:
if [x for x in user_input if x.startswith("acc_") and not user_input[x]]:
self._errors["base"] = "acc"
return await self._show_config_form(user_input)

self._user_input = user_input

return await self.async_step_device(user_input)

## Initial form
Expand Down Expand Up @@ -112,24 +133,33 @@ async def _show_config_form(self, user_input):
"acc_untested", default=user_input.get("acc_untested", False)
): bool,
vol.Required("acc_disable", default=user_input.get("acc_disable", False)): bool,
vol.Optional(
"experimental", default=user_input.get("experimental", True)
): bool,
}
),
errors=self._errors,
)

async def async_step_device_done(self, _user_input):
async def async_step_device_done(self, user_input: dict[str, bool] | None = None):
"""Handle device steps"""
if self._reauth:
existing_entry = self.hass.config_entries.async_get_entry(self.context["entry_id"])
self.hass.config_entries.async_update_entry(
existing_entry, data={"token": self.activation.access_token}
existing_entry, data={**existing_entry.data, "token": self.activation.access_token}
)
await self.hass.config_entries.async_reload(existing_entry.entry_id)
return self.async_abort(reason="reauth_successful")

return self.async_create_entry(title="", data={"token": self.activation.access_token})
return self.async_create_entry(
title="",
data={
"token": self.activation.access_token,
"experimental": self._user_input.get("experimental", False),
},
)

async def async_step_reauth(self, user_input=None):
async def async_step_reauth(self, _user_input=None):
"""Perform reauth upon an API authentication error."""
return await self.async_step_reauth_confirm()

Expand Down Expand Up @@ -175,8 +205,15 @@ async def async_step_user(self, user_input=None):
if hacs.configuration.config_type == ConfigurationType.YAML:
schema = {vol.Optional("not_in_use", default=""): str}
else:
schema = hacs_config_option_schema(self.config_entry.options)
del schema["frontend_repo"]
del schema["frontend_repo_url"]
schema = {
vol.Optional(SIDEPANEL_TITLE, default=hacs.configuration.sidepanel_title): str,
vol.Optional(SIDEPANEL_ICON, default=hacs.configuration.sidepanel_icon): str,
vol.Optional(RELEASE_LIMIT, default=hacs.configuration.release_limit): int,
vol.Optional(COUNTRY, default=hacs.configuration.country): vol.In(LOCALE),
vol.Optional(APPDAEMON, default=hacs.configuration.appdaemon): bool,
vol.Optional(NETDAEMON, default=hacs.configuration.netdaemon): bool,
vol.Optional(DEBUG, default=hacs.configuration.debug): bool,
vol.Optional(EXPERIMENTAL, default=hacs.configuration.experimental): bool,
}

return self.async_show_form(step_id="user", data_schema=vol.Schema(schema))
5 changes: 3 additions & 2 deletions custom_components/hacs/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
"data": {
"acc_logs": "I know how to access Home Assistant logs",
"acc_addons": "I know that there are no add-ons in HACS",
"acc_untested": "I know that everything inside HACS is custom and untested by Home Assistant",
"acc_disable": "I know that if I get issues with Home Assistant I should disable all my custom_components"
"acc_untested": "I know that everything inside HACS including HACS itself is custom and untested by Home Assistant",
"acc_disable": "I know that if I get issues with Home Assistant I should disable all my custom_components",
"experimental": "Enable experimental features, this is what eventually will become HACS 2.0.0, if you enable it now you do not need to do anything when 2.0.0 is released."
},
"description": "Before you can setup HACS you need to acknowledge the following"
},
Expand Down