mirror of
https://github.com/home-assistant/core.git
synced 2025-11-09 02:49:40 +00:00
Airtouch4 integration (#43513)
* airtouch 4 climate control integration * enhance tests for airtouch. Fix linting issues * Fix tests * rework tests * fix latest qa issues * Clean up * add already_configured message * Use common string * further qa fixes * simplify airtouch4 domain storage Co-authored-by: Franck Nijhof <git@frenck.dev> Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
50
homeassistant/components/airtouch4/config_flow.py
Normal file
50
homeassistant/components/airtouch4/config_flow.py
Normal file
@@ -0,0 +1,50 @@
|
||||
"""Config flow for AirTouch4."""
|
||||
from airtouch4pyapi import AirTouch, AirTouchStatus
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.const import CONF_HOST
|
||||
|
||||
from .const import DOMAIN
|
||||
|
||||
DATA_SCHEMA = vol.Schema({vol.Required(CONF_HOST): str})
|
||||
|
||||
|
||||
class AirtouchConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
"""Handle an Airtouch config flow."""
|
||||
|
||||
VERSION = 1
|
||||
|
||||
async def async_step_user(self, user_input=None):
|
||||
"""Handle a flow initialized by the user."""
|
||||
if user_input is None:
|
||||
return self.async_show_form(step_id="user", data_schema=DATA_SCHEMA)
|
||||
|
||||
errors = {}
|
||||
|
||||
host = user_input[CONF_HOST]
|
||||
self._async_abort_entries_match({CONF_HOST: host})
|
||||
|
||||
airtouch = AirTouch(host)
|
||||
await airtouch.UpdateInfo()
|
||||
airtouch_status = airtouch.Status
|
||||
airtouch_has_groups = bool(
|
||||
airtouch.Status == AirTouchStatus.OK and airtouch.GetGroups()
|
||||
)
|
||||
|
||||
if airtouch_status != AirTouchStatus.OK:
|
||||
errors["base"] = "cannot_connect"
|
||||
elif not airtouch_has_groups:
|
||||
errors["base"] = "no_units"
|
||||
|
||||
if errors:
|
||||
return self.async_show_form(
|
||||
step_id="user", data_schema=DATA_SCHEMA, errors=errors
|
||||
)
|
||||
|
||||
return self.async_create_entry(
|
||||
title=user_input[CONF_HOST],
|
||||
data={
|
||||
CONF_HOST: user_input[CONF_HOST],
|
||||
},
|
||||
)
|
||||
Reference in New Issue
Block a user