"""Config flow for Toggl integration."""
import logging
import voluptuous as vol
from homeassistant import config_entries, core, exceptions
from .const import DOMAIN  # pylint:disable=unused-import

_LOGGER = logging.getLogger(__name__)
DATA_SCHEMA = vol.Schema({"token": str})


class TogglHub:
    """Hub for TogglPy
    """

    def __init__(self, token):
        """Initialize."""
        self.token = token

    async def authenticate(self, token) -> bool:
        """Test if we can authenticate with the host."""
        return True


async def validate_input(hass: core.HomeAssistant, data):
    """Validate the user input allows us to connect.

    Data has the keys from DATA_SCHEMA with values provided by the user.
    """
    hub = TogglHub(data["token"])

    if not await hub.authenticate(data["token"]):
        raise InvalidAuth

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

    # Return info that you want to store in the config entry.
    return {"title": "Toggl"}


class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
    """Handle a config flow for Toggl."""

    VERSION = 1
    CONNECTION_CLASS = config_entries.CONN_CLASS_CLOUD_POLL

    async def async_step_user(self, user_input=None):
        """Handle the initial step."""
        errors = {}
        if user_input is not None:
            try:
                info = await validate_input(self.hass, user_input)
                return self.async_create_entry(title=info["title"], data=user_input)
            except CannotConnect:
                errors["base"] = "cannot_connect"
            except InvalidAuth:
                errors["base"] = "invalid_auth"
            except Exception:  # pylint: disable=broad-except
                _LOGGER.exception("Unexpected exception")
                errors["base"] = "unknown"
        return self.async_show_form(
            step_id="user", data_schema=DATA_SCHEMA, errors=errors
        )


class CannotConnect(exceptions.HomeAssistantError):
    """Error to indicate we cannot connect."""


class InvalidAuth(exceptions.HomeAssistantError):
    """Error to indicate there is invalid auth."""

73b909dfa7e81c2126a6bf5c7d7d8863e507a182
<mask token>


class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
    <mask token>
    VERSION = 1
    CONNECTION_CLASS = config_entries.CONN_CLASS_CLOUD_POLL

    async def async_step_user(self, user_input=None):
        """Handle the initial step."""
        errors = {}
        if user_input is not None:
            try:
                info = await validate_input(self.hass, user_input)
                return self.async_create_entry(title=info['title'], data=
                    user_input)
            except CannotConnect:
                errors['base'] = 'cannot_connect'
            except InvalidAuth:
                errors['base'] = 'invalid_auth'
            except Exception:
                _LOGGER.exception('Unexpected exception')
                errors['base'] = 'unknown'
        return self.async_show_form(step_id='user', data_schema=DATA_SCHEMA,
            errors=errors)


class CannotConnect(exceptions.HomeAssistantError):
    """Error to indicate we cannot connect."""


class InvalidAuth(exceptions.HomeAssistantError):
    """Error to indicate there is invalid auth."""

<mask token>


class TogglHub:
    <mask token>
    <mask token>

    async def authenticate(self, token) ->bool:
        """Test if we can authenticate with the host."""
        return True


<mask token>


class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
    """Handle a config flow for Toggl."""
    VERSION = 1
    CONNECTION_CLASS = config_entries.CONN_CLASS_CLOUD_POLL

    async def async_step_user(self, user_input=None):
        """Handle the initial step."""
        errors = {}
        if user_input is not None:
            try:
                info = await validate_input(self.hass, user_input)
                return self.async_create_entry(title=info['title'], data=
                    user_input)
            except CannotConnect:
                errors['base'] = 'cannot_connect'
            except InvalidAuth:
                errors['base'] = 'invalid_auth'
            except Exception:
                _LOGGER.exception('Unexpected exception')
                errors['base'] = 'unknown'
        return self.async_show_form(step_id='user', data_schema=DATA_SCHEMA,
            errors=errors)


class CannotConnect(exceptions.HomeAssistantError):
    """Error to indicate we cannot connect."""


class InvalidAuth(exceptions.HomeAssistantError):
    """Error to indicate there is invalid auth."""

<mask token>


class TogglHub:
    """Hub for TogglPy
    """

    def __init__(self, token):
        """Initialize."""
        self.token = token

    async def authenticate(self, token) ->bool:
        """Test if we can authenticate with the host."""
        return True


async def validate_input(hass: core.HomeAssistant, data):
    """Validate the user input allows us to connect.

    Data has the keys from DATA_SCHEMA with values provided by the user.
    """
    hub = TogglHub(data['token'])
    if not await hub.authenticate(data['token']):
        raise InvalidAuth
    return {'title': 'Toggl'}


class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
    """Handle a config flow for Toggl."""
    VERSION = 1
    CONNECTION_CLASS = config_entries.CONN_CLASS_CLOUD_POLL

    async def async_step_user(self, user_input=None):
        """Handle the initial step."""
        errors = {}
        if user_input is not None:
            try:
                info = await validate_input(self.hass, user_input)
                return self.async_create_entry(title=info['title'], data=
                    user_input)
            except CannotConnect:
                errors['base'] = 'cannot_connect'
            except InvalidAuth:
                errors['base'] = 'invalid_auth'
            except Exception:
                _LOGGER.exception('Unexpected exception')
                errors['base'] = 'unknown'
        return self.async_show_form(step_id='user', data_schema=DATA_SCHEMA,
            errors=errors)


class CannotConnect(exceptions.HomeAssistantError):
    """Error to indicate we cannot connect."""


class InvalidAuth(exceptions.HomeAssistantError):
    """Error to indicate there is invalid auth."""

<mask token>
import logging
import voluptuous as vol
from homeassistant import config_entries, core, exceptions
from .const import DOMAIN
_LOGGER = logging.getLogger(__name__)
DATA_SCHEMA = vol.Schema({'token': str})


class TogglHub:
    """Hub for TogglPy
    """

    def __init__(self, token):
        """Initialize."""
        self.token = token

    async def authenticate(self, token) ->bool:
        """Test if we can authenticate with the host."""
        return True


async def validate_input(hass: core.HomeAssistant, data):
    """Validate the user input allows us to connect.

    Data has the keys from DATA_SCHEMA with values provided by the user.
    """
    hub = TogglHub(data['token'])
    if not await hub.authenticate(data['token']):
        raise InvalidAuth
    return {'title': 'Toggl'}


class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
    """Handle a config flow for Toggl."""
    VERSION = 1
    CONNECTION_CLASS = config_entries.CONN_CLASS_CLOUD_POLL

    async def async_step_user(self, user_input=None):
        """Handle the initial step."""
        errors = {}
        if user_input is not None:
            try:
                info = await validate_input(self.hass, user_input)
                return self.async_create_entry(title=info['title'], data=
                    user_input)
            except CannotConnect:
                errors['base'] = 'cannot_connect'
            except InvalidAuth:
                errors['base'] = 'invalid_auth'
            except Exception:
                _LOGGER.exception('Unexpected exception')
                errors['base'] = 'unknown'
        return self.async_show_form(step_id='user', data_schema=DATA_SCHEMA,
            errors=errors)


class CannotConnect(exceptions.HomeAssistantError):
    """Error to indicate we cannot connect."""


class InvalidAuth(exceptions.HomeAssistantError):
    """Error to indicate there is invalid auth."""

"""Config flow for Toggl integration."""
import logging
import voluptuous as vol
from homeassistant import config_entries, core, exceptions
from .const import DOMAIN  # pylint:disable=unused-import

_LOGGER = logging.getLogger(__name__)
DATA_SCHEMA = vol.Schema({"token": str})


class TogglHub:
    """Hub for TogglPy
    """

    def __init__(self, token):
        """Initialize."""
        self.token = token

    async def authenticate(self, token) -> bool:
        """Test if we can authenticate with the host."""
        return True


async def validate_input(hass: core.HomeAssistant, data):
    """Validate the user input allows us to connect.

    Data has the keys from DATA_SCHEMA with values provided by the user.
    """
    hub = TogglHub(data["token"])

    if not await hub.authenticate(data["token"]):
        raise InvalidAuth

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

    # Return info that you want to store in the config entry.
    return {"title": "Toggl"}


class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
    """Handle a config flow for Toggl."""

    VERSION = 1
    CONNECTION_CLASS = config_entries.CONN_CLASS_CLOUD_POLL

    async def async_step_user(self, user_input=None):
        """Handle the initial step."""
        errors = {}
        if user_input is not None:
            try:
                info = await validate_input(self.hass, user_input)
                return self.async_create_entry(title=info["title"], data=user_input)
            except CannotConnect:
                errors["base"] = "cannot_connect"
            except InvalidAuth:
                errors["base"] = "invalid_auth"
            except Exception:  # pylint: disable=broad-except
                _LOGGER.exception("Unexpected exception")
                errors["base"] = "unknown"
        return self.async_show_form(
            step_id="user", data_schema=DATA_SCHEMA, errors=errors
        )


class CannotConnect(exceptions.HomeAssistantError):
    """Error to indicate we cannot connect."""


class InvalidAuth(exceptions.HomeAssistantError):
    """Error to indicate there is invalid auth."""
