core/homeassistant/components/ihc/__init__.py

73 lines
2.2 KiB
Python
Raw Normal View History

"""Support for IHC devices."""
import logging
2018-04-06 16:06:47 +00:00
2019-12-04 13:09:57 +00:00
from ihcsdk.ihccontroller import IHCController
import voluptuous as vol
from homeassistant.const import CONF_PASSWORD, CONF_URL, CONF_USERNAME
2022-01-23 04:33:10 +00:00
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.typing import ConfigType
2022-01-24 11:07:54 +00:00
from .auto_setup import autosetup_ihc_products
from .const import (
CONF_AUTOSETUP,
CONF_INFO,
DOMAIN,
IHC_CONTROLLER,
IHC_CONTROLLER_INDEX,
)
from .manual_setup import IHC_SCHEMA, get_manual_configuration
2022-01-23 04:33:10 +00:00
from .service_functions import setup_service_functions
_LOGGER = logging.getLogger(__name__)
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
)
def setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the IHC integration."""
conf = config[DOMAIN]
Add support for multiple IHC controllers (#18058) * Added support for secondary IHC controller Most IHC systems only have one controller but the system can be setup with a linked secondary controller. I have updated the code to have it support both primary and secondary controller. Existing configuration is not impacted and secondary controller can be setup the same way, with similar settings nested under 'secondary' in the configuration * Update __init__.py * Update __init__.py * Update __init__.py * Update ihc.py * Update ihc.py * Update ihc.py * Update __init__.py * Update ihc.py * Update ihc.py * Update ihc.py * Update __init__.py * Update ihc.py * Update ihc.py * Update __init__.py * Update ihc.py * Update __init__.py * Update const.py * Update ihc.py * Update ihc.py * Update ihc.py * Update ihc.py * Update ihc.py * Update ihc.py * Update ihc.py * Update ihc.py * Update ihc.py * Update ihc.py * Update ihc.py * Update ihc.py * Update __init__.py * Update __init__.py * Update __init__.py * Update const.py * Update __init__.py * Update ihc.py * Update ihc.py * Update ihc.py * Update ihc.py * Update __init__.py * Update __init__.py * Update ihc.py * Update ihc.py * Update ihc.py * Update __init__.py * Update ihc.py * Update ihc.py * Update __init__.py * Update ihc.py * Update ihc.py * Update __init__.py * Update ihc.py * Update ihc.py * Update ihc.py * Update ihc.py * Update ihc.py * Update ihc.py * Update ihc.py * Update ihc.py * Update __init__.py * Update __init__.py * Update ihc.py * Update __init__.py * Update __init__.py * Update __init__.py * Update __init__.py * Update __init__.py * Update __init__.py indentation was incorrect for "load_platform" in "get_manual_configuration". Load_platform was not called with the correct component name
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
def ihc_setup(
hass: HomeAssistant,
config: ConfigType,
controller_conf: ConfigType,
controller_index: int,
) -> bool:
"""Set up the IHC integration."""
url = controller_conf[CONF_URL]
username = controller_conf[CONF_USERNAME]
password = controller_conf[CONF_PASSWORD]
Add support for multiple IHC controllers (#18058) * Added support for secondary IHC controller Most IHC systems only have one controller but the system can be setup with a linked secondary controller. I have updated the code to have it support both primary and secondary controller. Existing configuration is not impacted and secondary controller can be setup the same way, with similar settings nested under 'secondary' in the configuration * Update __init__.py * Update __init__.py * Update __init__.py * Update ihc.py * Update ihc.py * Update ihc.py * Update __init__.py * Update ihc.py * Update ihc.py * Update ihc.py * Update __init__.py * Update ihc.py * Update ihc.py * Update __init__.py * Update ihc.py * Update __init__.py * Update const.py * Update ihc.py * Update ihc.py * Update ihc.py * Update ihc.py * Update ihc.py * Update ihc.py * Update ihc.py * Update ihc.py * Update ihc.py * Update ihc.py * Update ihc.py * Update ihc.py * Update __init__.py * Update __init__.py * Update __init__.py * Update const.py * Update __init__.py * Update ihc.py * Update ihc.py * Update ihc.py * Update ihc.py * Update __init__.py * Update __init__.py * Update ihc.py * Update ihc.py * Update ihc.py * Update __init__.py * Update ihc.py * Update ihc.py * Update __init__.py * Update ihc.py * Update ihc.py * Update __init__.py * Update ihc.py * Update ihc.py * Update ihc.py * Update ihc.py * Update ihc.py * Update ihc.py * Update ihc.py * Update ihc.py * Update __init__.py * Update __init__.py * Update ihc.py * Update __init__.py * Update __init__.py * Update __init__.py * Update __init__.py * Update __init__.py * Update __init__.py indentation was incorrect for "load_platform" in "get_manual_configuration". Load_platform was not called with the correct component name
2018-11-22 08:45:40 +00:00
ihc_controller = IHCController(url, username, password)
if not ihc_controller.authenticate():
2018-04-06 16:06:47 +00:00
_LOGGER.error("Unable to authenticate on IHC controller")
return False
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,
}
if controller_conf[CONF_AUTOSETUP] and not autosetup_ihc_products(
2019-07-31 19:25:30 +00:00
hass, config, ihc_controller, controller_id
):
return False
get_manual_configuration(hass, config, controller_conf, controller_id)
# We only want to register the service functions once for the first controller
if controller_index == 0:
setup_service_functions(hass)
return True