-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a27a109
commit bb76450
Showing
9 changed files
with
223 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import logging | ||
from typing import Any, Dict, Optional | ||
from collections import OrderedDict | ||
|
||
from homeassistant import config_entries, core | ||
from homeassistant.const import CONF_USERNAME, CONF_PASSWORD, CONF_REGION | ||
from homeassistant.core import callback | ||
from homeassistant.helpers.aiohttp_client import async_get_clientsession | ||
import homeassistant.helpers.config_validation as cv | ||
from homeassistant.helpers.entity_registry import ( | ||
async_entries_for_config_entry | ||
) | ||
from homeassistant.helpers.selector import ( | ||
TextSelector, | ||
TextSelectorConfig, | ||
TextSelectorType, | ||
) | ||
import voluptuous as vol | ||
from .const import * | ||
|
||
from .pydreo import PyDreo | ||
|
||
_LOGGER = logging.getLogger("dreo") | ||
|
||
class DreoFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): | ||
"""Dreo Custom config flow.""" | ||
|
||
# The schema version of the entries that it creates | ||
# Home Assistant will call your migrate method if the version changes | ||
VERSION = 1 | ||
|
||
def __init__(self) -> None: | ||
"""Instantiate config flow.""" | ||
self._username = None | ||
self._password = None | ||
self.data_schema = OrderedDict() | ||
self.data_schema[vol.Required(CONF_USERNAME)] = str | ||
self.data_schema[vol.Required(CONF_PASSWORD)] = str | ||
|
||
@callback | ||
def _show_form(self, errors=None): | ||
"""Show form to the user.""" | ||
return self.async_show_form( | ||
step_id="user", | ||
data_schema=vol.Schema(self.data_schema), | ||
errors=errors if errors else {}, | ||
) | ||
|
||
async def async_step_user(self, user_input=None): | ||
"""Handle a flow start.""" | ||
if self._async_current_entries(): | ||
return self.async_abort(reason="single_instance_allowed") | ||
|
||
if not user_input: | ||
return self._show_form() | ||
|
||
self._username = user_input[CONF_USERNAME] | ||
self._password = user_input[CONF_PASSWORD] | ||
|
||
manager = PyDreo(self._username, self._password, "us") | ||
login = await self.hass.async_add_executor_job(manager.login) | ||
if not login: | ||
return self._show_form(errors={"base": "invalid_auth"}) | ||
|
||
return self.async_create_entry( | ||
title=self._username, | ||
data={CONF_USERNAME: self._username, CONF_PASSWORD: self._password}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.