def _fetch_isy_configuration(address, port, username, password, use_https, tls_ver, webroot): """Validate and fetch the configuration from the ISY.""" try: isy_conn = Connection( address, port, username, password, use_https, tls_ver, webroot=webroot, ) except ValueError as err: raise InvalidAuth(err.args[0]) from err return Configuration(xml=isy_conn.get_config())
async def validate_input(hass: core.HomeAssistant, data: dict[str, Any]) -> dict[str, str]: """Validate the user input allows us to connect. Data has the keys from DATA_SCHEMA with values provided by the user. """ user = data[CONF_USERNAME] password = data[CONF_PASSWORD] host = urlparse(data[CONF_HOST]) tls_version = data.get(CONF_TLS_VER) if host.scheme == SCHEME_HTTP: https = False port = host.port or HTTP_PORT session = aiohttp_client.async_create_clientsession( hass, verify_ssl=False, cookie_jar=CookieJar(unsafe=True)) elif host.scheme == SCHEME_HTTPS: https = True port = host.port or HTTPS_PORT session = aiohttp_client.async_get_clientsession(hass) else: _LOGGER.error("The isy994 host value in configuration is invalid") raise InvalidHost # Connect to ISY controller. isy_conn = Connection( host.hostname, port, user, password, use_https=https, tls_ver=tls_version, webroot=host.path, websession=session, ) try: async with async_timeout.timeout(30): isy_conf_xml = await isy_conn.test_connection() except ISYInvalidAuthError as error: raise InvalidAuth from error except ISYConnectionError as error: raise CannotConnect from error try: isy_conf = Configuration(xml=isy_conf_xml) except ISYResponseParseError as error: raise CannotConnect from error if not isy_conf or "name" not in isy_conf or not isy_conf["name"]: raise CannotConnect # Return info that you want to store in the config entry. return { "title": f"{isy_conf['name']} ({host.hostname})", "uuid": isy_conf["uuid"] }
def main(arguments): """Execute primary loop.""" logging.basicConfig(format=LOG_FORMAT, datefmt=LOG_DATE_FORMAT, level=LOG_LEVEL) # Test the connection to ISY controller. try: Connection( address=ADDRESS, port=PORT, username=USERNAME, password=PASSWORD, use_https=USE_HTTPS, tls_ver=TLS_VER, log=_LOGGER, webroot=WEBROOT, ) except ValueError as err: _LOGGER.error( "Failed to connect to the ISY, " "please adjust settings and try again. Error: \n%s", err.args[0], ) return _LOGGER.info("ISY connected! Connection properties valid, continuing.") # Actually connect to the ISY and download full configuration. isy = ISY( address=ADDRESS, port=PORT, username=USERNAME, password=PASSWORD, use_https=USE_HTTPS, tls_ver=TLS_VER, log=_LOGGER, webroot=WEBROOT, ) _LOGGER.info("ISY connected: %s", isy.connected) if not isy.connected: _LOGGER.error( "Failed to connect to the ISY, please adjust settings and try again." ) return # Print a representation of all the Nodes _LOGGER.debug(repr(isy.nodes)) # Get the rest of the detailed status information from the ISY # not originally reported. This includes statuses for all NodeServer nodes. isy.nodes.update() # Connect to the Event Stream and print events in the Debug Log. isy.auto_update = True try: while True: sleep(10) except KeyboardInterrupt: _LOGGER.warning("KeyboardInterrupt received. Disconnecting!") if isy.connected and isy.auto_update: isy.auto_update = False
def main(arguments): """Execute primary loop.""" fmt = "%(asctime)s %(levelname)s [%(name)s] %(message)s" datefmt = "%Y-%m-%d %H:%M:%S" logging.basicConfig(format=fmt, datefmt=datefmt, level=logging.DEBUG) # Test the connection to ISY controller. try: Connection( address=ADDRESS, port=PORT, username=USERNAME, password=PASSWORD, use_https=USE_HTTPS, tls_ver=TLS_VER, log=_LOGGER, webroot=WEBROOT, ) except ValueError as err: _LOGGER.error( "Failed to connect to the ISY, " "please adjust settings and try again. Error: \n%s", err.args[0], ) return _LOGGER.info("ISY connected! Connection properties valid, continuing.") # Actually connect to the ISY and download full configuration. isy = ISY( address=ADDRESS, port=PORT, username=USERNAME, password=PASSWORD, use_https=USE_HTTPS, tls_ver=TLS_VER, log=_LOGGER, webroot=WEBROOT, ) _LOGGER.info("ISY connected: %s", isy.connected) # Print a representation of all the Nodes _LOGGER.debug(repr(isy.nodes)) if isy.connected: # Connect to the Event Stream and print events in the Debug Log. isy.auto_update = True else: _LOGGER.error( "Failed to connect to the ISY, please adjust settings and try again." ) return try: while True: sleep(10) except KeyboardInterrupt: _LOGGER.warning("KeyboardInterrupt received. Disconnecting!") if isy.connected and isy.auto_update: isy.auto_update = False