Initial commit

This commit is contained in:
2022-10-10 22:41:15 +02:00
commit 926e652f67
12 changed files with 779 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
import voluptuous as vol
import logging
from homeassistant.config_entries import ConfigFlow
from .pyplejd import api
_LOGGER = logging.getLogger(__name__)
class PlejdConfigFlow(ConfigFlow, domain="plejd"):
VERSION = 1
async def async_step_user(self, info=None):
if info is None:
return self.async_show_form(
step_id="user",
data_schema=vol.Schema(
{
vol.Required("username"): str,
vol.Required("password"): str
}
)
)
_LOGGER.info("Log in with %s %s", info["username"], info["password"])
self.credentials = info
return await self.async_step_picksite()
async def async_step_picksite(self, info=None):
if info is None:
sites = await api.get_sites(self.credentials["username"], self.credentials["password"])
_LOGGER.info(sites)
return self.async_show_form(
step_id="picksite",
data_schema=vol.Schema(
{
vol.Required("site"): vol.In(
{
site["site"]["siteId"]: site["site"]["title"]
for site in sites
}
)
}
)
)
data={
"username": self.credentials["username"],
"password": self.credentials["password"],
"siteId": info["site"]
}
_LOGGER.debug("Saving: %s", data)
return self.async_create_entry(title="Plejd", data=data)