"""The broadlink component.""" import asyncio from base64 import b64decode, b64encode from binascii import unhexlify from datetime import timedelta import logging import re import socket import voluptuous as vol from homeassistant.const import CONF_HOST from homeassistant.core import callback import homeassistant.helpers.config_validation as cv from homeassistant.util.dt import utcnow from .const import CONF_PACKET, DOMAIN, SERVICE_LEARN, SERVICE_SEND _LOGGER = logging.getLogger(__name__) DEFAULT_RETRY = 3 def data_packet(value): """Decode a data packet given for broadlink.""" value = cv.string(value) extra = len(value) % 4 if extra > 0: value = value + ("=" * (4 - extra)) return b64decode(value) def hostname(value): """Validate a hostname.""" host = str(value).lower() if len(host) > 253: raise ValueError if host[-1] == ".": host = host[:-1] allowed = re.compile(r"(?!-)[a-z\d-]{1,63}(?