Skip to content
Draft
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
20 changes: 15 additions & 5 deletions custom_components/growstuff/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand All @@ -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):
Expand Down Expand Up @@ -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."""

2 changes: 2 additions & 0 deletions custom_components/growstuff/const.py
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
4 changes: 2 additions & 2 deletions custom_components/growstuff/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
},
Expand Down