1 """The Schluter DITRA-HEAT integration."""
5 from requests
import RequestException, Session
6 from schluter.api
import Api
7 from schluter.authenticator
import AuthenticationState, Authenticator
8 import voluptuous
as vol
16 from .const
import DOMAIN
18 _LOGGER = logging.getLogger(__name__)
19 DATA_SCHLUTER_SESSION =
"schluter_session"
20 DATA_SCHLUTER_API =
"schluter_api"
21 SCHLUTER_CONFIG_FILE =
".schluter.conf"
24 CONFIG_SCHEMA = vol.Schema(
26 vol.Required(DOMAIN): vol.Schema(
28 vol.Required(CONF_USERNAME): cv.string,
29 vol.Required(CONF_PASSWORD): cv.string,
33 extra=vol.ALLOW_EXTRA,
37 def setup(hass: HomeAssistant, config: ConfigType) -> bool:
38 """Set up the Schluter component."""
39 _LOGGER.debug(
"Starting setup of schluter")
42 api_http_session = Session()
43 api = Api(timeout=API_TIMEOUT, http_session=api_http_session)
45 authenticator = Authenticator(
47 conf.get(CONF_USERNAME),
48 conf.get(CONF_PASSWORD),
49 session_id_cache_file=hass.config.path(SCHLUTER_CONFIG_FILE),
54 authentication = authenticator.authenticate()
55 except RequestException
as ex:
56 _LOGGER.error(
"Unable to connect to Schluter service: %s", ex)
59 state = authentication.state
61 if state == AuthenticationState.AUTHENTICATED:
63 DATA_SCHLUTER_API: api,
64 DATA_SCHLUTER_SESSION: authentication.session_id,
66 discovery.load_platform(hass, Platform.CLIMATE, DOMAIN, {}, config)
68 if state == AuthenticationState.BAD_PASSWORD:
69 _LOGGER.error(
"Invalid password provided")
71 if state == AuthenticationState.BAD_EMAIL:
72 _LOGGER.error(
"Invalid email provided")
75 _LOGGER.error(
"Unknown set up error: %s", state)
bool setup(HomeAssistant hass, ConfigType config)