Skip to content

Commit

Permalink
Add config flow again
Browse files Browse the repository at this point in the history
  • Loading branch information
arjenbos committed Oct 30, 2023
1 parent 60d574b commit 30f48a9
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions custom_components/alpha_innotec/config_flow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import logging
from typing import Any

import voluptuous as vol
from homeassistant import config_entries, exceptions
from homeassistant.data_entry_flow import FlowResult

from .const import DOMAIN
from .controller_api import ControllerAPI
from .gateway_api import GatewayAPI

_LOGGER = logging.getLogger(__name__)

DATA_SCHEMA = vol.Schema({
vol.Required("gateway_ip", description="Please enter the IP address of your gateway."): str,
vol.Required("gateway_password", description="Please enter the password of your gateway."): str,
vol.Required("controller_ip", description="Please enter the IP address of your controller."): str,
vol.Required("controller_username", description="The username for your controller."): str,
vol.Required("controller_password", description="The password for your controller."): str
})


def validate_input(data: dict) -> dict:
controller_api = ControllerAPI(data["controller_ip"], data["controller_username"], data["controller_password"])
gateway_api = GatewayAPI(data['gateway_ip'], data['gateway_password'])

try:
controller_api.login()
gateway_api.login()
system_information = controller_api.system_information()

return system_information
except Exception as exception:
_LOGGER.debug("Exception: %s", exception)
raise CannotConnect


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

VERSION = 1

CONNECTION_CLASS = config_entries.CONN_CLASS_LOCAL_POLL

async def async_step_user(
self, user_input: dict[str, Any] | None = None
) -> FlowResult:
"""Invoke when a user initiates a flow via the user interface."""

errors = {}

if user_input is not None:
try:
system_information = await self.hass.async_add_executor_job(validate_input, user_input)

return self.async_create_entry(title=system_information.get("name", "Alpha Home"), data=user_input)
except CannotConnect:
errors["base"] = "cannot_connect"
except Exception as 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."""

1 comment on commit 30f48a9

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HA Alpha Innotec Coverage

HA Alpha Innotec
FileStmtsMissCoverMissing
__init__.py21957%19–20, 22, 27, 29, 34, 36–37, 39
api.py44295%48, 51
base_coordinator.py36360%2, 4, 6, 8–11, 13, 16, 18–21, 23, 25–26, 28–31, 33–34, 36–38, 40, 42–44, 46, 58–60, 62–64
binary_sensor.py58580%2, 4–5, 7, 9–12, 17–19, 21, 24, 27, 29, 31, 33, 35, 37–38, 45, 48, 51, 53, 60, 62, 69, 71, 73–74, 76–77, 79–80, 89, 91, 93, 96, 99, 101–104, 106–107, 109, 117–119, 121–122, 124, 126–128, 130–132
climate.py81810%2, 4–5, 7, 9, 13–15, 20–23, 25, 28, 31–32, 34, 36, 38, 40–41, 49, 52, 55, 57, 64–65, 67, 73, 76, 79–81, 85, 87–93, 95–96, 98, 106–107, 109, 111–112, 115, 117–119, 121–122, 124–126, 128–129, 131, 133, 136–137, 139–141, 143, 145–146, 148, 150, 152–154, 156–157, 159, 161–162, 165
config_flow.py371559%24–25, 27–30, 32–35, 57–61
const.py70100% 
controller_api.py765922%17–18, 20–21, 23–26, 28, 30–33, 35, 38, 40, 43, 45, 50, 52–55, 57, 59–60, 62, 64, 71, 73, 80–81, 83, 85, 87, 89, 91–92, 94, 97, 100–101, 103–106, 108, 111, 114, 120, 122–126, 138–140, 142
gateway_api.py624724%17–19, 21–23, 26–27, 29–30, 32–35, 37, 39–42, 44, 47, 49, 52, 54, 59, 61, 63–65, 67, 69–70, 72, 74, 77, 79, 81–82, 84, 87–88, 90, 93, 96–98, 100
sensor.py46460%2, 4–5, 7–10, 15–18, 20, 23, 26–27, 29, 31, 33, 35–38, 40, 47, 50, 53, 55, 62–63, 65, 71, 74, 77–78, 80, 82–86, 88–89, 91, 99–100, 102
structs
   Thermostat.py11918%8–16
TOTAL47936224% 

Tests Skipped Failures Errors Time
3 0 💤 0 ❌ 0 🔥 0.925s ⏱️

Please sign in to comment.