DEVELOPMENT ENVIRONMENT

~liljamo/ha-ouman-eh800

ref: 13538155ef2f8ee6e80b088226804037c8c03c56 ha-ouman-eh800/custom_components/ouman_eh800/config_flow.py -rw-r--r-- 1.5 KiB
13538155Jonni Liljamo feat: fire an event when operation mode changes 11 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"""Ouman EH-800 config flow"""

import logging

from typing import Any

import voluptuous as vol

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
):  # pylint: disable=too-few-public-methods
    """Ouman EH-800 config flow"""

    VERSION = 1

    async def _create_entry(
        self, host: str, port: int, username: str, password: str
    ) -> ConfigFlowResult:
        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],
        )