2019-02-14 15:01:46 +00:00
|
|
|
"""Support for IHC devices."""
|
2024-03-08 18:15:59 +00:00
|
|
|
|
2018-01-20 15:29:50 +00:00
|
|
|
import logging
|
2018-04-06 16:06:47 +00:00
|
|
|
|
2019-12-04 13:09:57 +00:00
|
|
|
from ihcsdk.ihccontroller import IHCController
|
2018-01-20 15:29:50 +00:00
|
|
|
import voluptuous as vol
|
2018-12-19 11:39:16 +00:00
|
|
|
|
2022-02-06 21:42:15 +00:00
|
|
|
from homeassistant.const import CONF_PASSWORD, CONF_URL, CONF_USERNAME
|
2022-01-23 04:33:10 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
2018-01-20 15:29:50 +00:00
|
|
|
import homeassistant.helpers.config_validation as cv
|
2022-01-05 11:14:13 +00:00
|
|
|
from homeassistant.helpers.typing import ConfigType
|
2018-01-20 15:29:50 +00:00
|
|
|
|
2022-01-24 11:07:54 +00:00
|
|
|
from .auto_setup import autosetup_ihc_products
|
2022-02-11 09:24:31 +00:00
|
|
|
from .const import (
|
|
|
|
CONF_AUTOSETUP,
|
|
|
|
CONF_INFO,
|
|
|
|
DOMAIN,
|
|
|
|
IHC_CONTROLLER,
|
|
|
|
IHC_CONTROLLER_INDEX,
|
|
|
|
)
|
2022-02-06 21:42:15 +00:00
|
|
|
from .manual_setup import IHC_SCHEMA, get_manual_configuration
|
2022-01-23 04:33:10 +00:00
|
|
|
from .service_functions import setup_service_functions
|
2019-03-21 05:56:46 +00:00
|
|
|
|
2018-12-19 11:39:16 +00:00
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
2018-01-20 15:29:50 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
CONFIG_SCHEMA = vol.Schema(
|
|
|
|
{DOMAIN: vol.Schema(vol.All(cv.ensure_list, [IHC_SCHEMA]))}, extra=vol.ALLOW_EXTRA
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-01-05 11:14:13 +00:00
|
|
|
def setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
2021-03-02 20:43:59 +00:00
|
|
|
"""Set up the IHC integration."""
|
2022-01-05 11:14:13 +00:00
|
|
|
conf = config[DOMAIN]
|
2018-11-22 08:45:40 +00:00
|
|
|
for index, controller_conf in enumerate(conf):
|
|
|
|
if not ihc_setup(hass, config, controller_conf, index):
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
2022-02-06 21:42:15 +00:00
|
|
|
def ihc_setup(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
config: ConfigType,
|
|
|
|
controller_conf: ConfigType,
|
2022-02-11 09:24:31 +00:00
|
|
|
controller_index: int,
|
2022-02-06 21:42:15 +00:00
|
|
|
) -> bool:
|
2021-03-02 20:43:59 +00:00
|
|
|
"""Set up the IHC integration."""
|
2022-02-06 21:42:15 +00:00
|
|
|
url = controller_conf[CONF_URL]
|
|
|
|
username = controller_conf[CONF_USERNAME]
|
|
|
|
password = controller_conf[CONF_PASSWORD]
|
2018-01-20 15:29:50 +00:00
|
|
|
|
2018-11-22 08:45:40 +00:00
|
|
|
ihc_controller = IHCController(url, username, password)
|
2018-01-20 15:29:50 +00:00
|
|
|
if not ihc_controller.authenticate():
|
2018-04-06 16:06:47 +00:00
|
|
|
_LOGGER.error("Unable to authenticate on IHC controller")
|
2018-01-20 15:29:50 +00:00
|
|
|
return False
|
2022-02-11 09:24:31 +00:00
|
|
|
controller_id: str = ihc_controller.client.get_system_info()["serial_number"]
|
|
|
|
# Store controller configuration
|
|
|
|
hass.data.setdefault(DOMAIN, {})
|
|
|
|
hass.data[DOMAIN][controller_id] = {
|
|
|
|
IHC_CONTROLLER: ihc_controller,
|
|
|
|
CONF_INFO: controller_conf[CONF_INFO],
|
|
|
|
IHC_CONTROLLER_INDEX: controller_index,
|
|
|
|
}
|
2022-02-06 21:42:15 +00:00
|
|
|
if controller_conf[CONF_AUTOSETUP] and not autosetup_ihc_products(
|
2019-07-31 19:25:30 +00:00
|
|
|
hass, config, ihc_controller, controller_id
|
|
|
|
):
|
2018-01-20 15:29:50 +00:00
|
|
|
return False
|
2022-02-06 21:42:15 +00:00
|
|
|
get_manual_configuration(hass, config, controller_conf, controller_id)
|
2021-01-30 11:46:50 +00:00
|
|
|
# We only want to register the service functions once for the first controller
|
2022-02-11 09:24:31 +00:00
|
|
|
if controller_index == 0:
|
2021-01-30 11:46:50 +00:00
|
|
|
setup_service_functions(hass)
|
2018-01-20 15:29:50 +00:00
|
|
|
return True
|