"""Adds config flow for Dune HD integration.""" import ipaddress import logging import re from pdunehd import DuneHDPlayer import voluptuous as vol from homeassistant import config_entries, exceptions from homeassistant.const import CONF_HOST from .const import DOMAIN _LOGGER = logging.getLogger(__name__) def host_valid(host): """Return True if hostname or IP address is valid.""" try: if ipaddress.ip_address(host).version == (4 or 6): return True except ValueError: if len(host) > 253: return False allowed = re.compile(r"(?!-)[A-Z\d\-\_]{1,63}(?