DEVELOPMENT ENVIRONMENT

~liljamo/ha-ouman-eh800

ref: a21df4529c0abd305baa27231561fa0a8b1ae0b2 ha-ouman-eh800/custom_components/ouman_eh800/config_flow.py -rw-r--r-- 1.5 KiB
a21df452Jonni Liljamo initial 19 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import logging
import voluptuous as vol

from typing import Any, Dict, Optional

from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
from .const import DOMAIN, DEFAULT_PORT, CONF_HOST, CONF_PORT, CONF_USERNAME, CONF_PASSWORD

_LOGGER = logging.getLogger(__name__)

USER_SCHEMA = vol.Schema(
        {
            vol.Required(CONF_HOST): str,
            vol.Required(CONF_PORT, default=DEFAULT_PORT): int,
            vol.Required(CONF_USERNAME): str,
            vol.Required(CONF_PASSWORD): str,
        }
)

class OumanEH800ConfigFlow(ConfigFlow, domain=DOMAIN):
    """Ouman EH-800 config flow"""

    VERSION = 1

    async def _create_entry(self, host: str, port: int, username: str, password: str) -> ConfigFlowResult:
        """Register new entry."""
        return self.async_create_entry(
                title=f"Ouman {host}",
                data={
                    CONF_HOST: host,
                    CONF_PORT: port,
                    CONF_USERNAME: username,
                    CONF_PASSWORD: password
                }
        )

    async def async_step_user(self, user_input: dict[str, Any] | None = None) -> ConfigFlowResult:
        if user_input is None:
            return self.async_show_form(
                step_id="user", data_schema=USER_SCHEMA
            )

        _LOGGER.debug(user_input)
        return await self._create_entry(user_input[CONF_HOST], user_input[CONF_PORT], user_input[CONF_USERNAME], user_input[CONF_PASSWORD])