diff --git a/custom_components/growstuff/config_flow.py b/custom_components/growstuff/config_flow.py index feb9b37..65e1a31 100644 --- a/custom_components/growstuff/config_flow.py +++ b/custom_components/growstuff/config_flow.py @@ -8,13 +8,19 @@ import voluptuous as vol from homeassistant import config_entries, exceptions +from homeassistant.const import CONF_API_TOKEN, CONF_USERNAME from homeassistant.core import HomeAssistant from .const import DOMAIN _LOGGER = logging.getLogger(__name__) -DATA_SCHEMA = vol.Schema({("member"): str}) +DATA_SCHEMA = vol.Schema( + { + vol.Required(CONF_USERNAME): str, + vol.Required(CONF_API_TOKEN): str, + } +) async def validate_input(hass: HomeAssistant, data: dict) -> dict[str, Any]: @@ -23,10 +29,14 @@ async def validate_input(hass: HomeAssistant, data: dict) -> dict[str, Any]: """ # Validate the data can be used to set up a connection. - if len(data["member"]) < 3: - raise InvalidData + if len(data[CONF_USERNAME]) < 3: + raise InvalidData - return {"title": data["member"]} + if len(data[CONF_API_TOKEN]) < 16: + raise InvalidData + + # Return info that you want to store in the config entry. + return {"title": data[CONF_USERNAME]} class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): @@ -68,6 +78,6 @@ async def async_step_user(self, user_input=None): class CannotConnect(exceptions.HomeAssistantError): """Error to indicate we cannot connect.""" + class InvalidData(exceptions.HomeAssistantError): """Error to indicate we bad data.""" - diff --git a/custom_components/growstuff/const.py b/custom_components/growstuff/const.py index d42b598..50ed85c 100644 --- a/custom_components/growstuff/const.py +++ b/custom_components/growstuff/const.py @@ -1,6 +1,8 @@ """Constants for growstuff integration.""" from homeassistant.const import Platform +from homeassistant.const import CONF_API_TOKEN, CONF_USERNAME + DOMAIN = "growstuff" _API_URL = "https://www.growstuff.org/api/v1" diff --git a/custom_components/growstuff/strings.json b/custom_components/growstuff/strings.json index cbbafce..f1dedaa 100644 --- a/custom_components/growstuff/strings.json +++ b/custom_components/growstuff/strings.json @@ -3,8 +3,8 @@ "step": { "user": { "data": { - "member": "[%key:common::config_flow::data::username%]", - "api_key": "[%key:common::config_flow::data::password%]" + "username": "Member ID", + "api_token": "API Token" } } },