def run_ota_impl_(remote_host, remote_port, password, filename): if is_ip_address(remote_host): _LOGGER.info("Connecting to %s", remote_host) ip = remote_host else: _LOGGER.info("Resolving IP address of %s", remote_host) try: ip = resolve_ip_address(remote_host) except EsphomeError as err: _LOGGER.error( "Error resolving IP address of %s. Is it connected to WiFi?", remote_host, ) _LOGGER.error( "(If this error persists, please set a static IP address: " "https://esphome.io/components/wifi.html#manual-ips)" ) raise OTAError(err) from err _LOGGER.info(" -> %s", ip) sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.settimeout(10.0) try: sock.connect((ip, remote_port)) except OSError as err: sock.close() _LOGGER.error("Connecting to %s:%s failed: %s", remote_host, remote_port, err) return 1 file_handle = open(filename, "rb") try: perform_ota(sock, password, file_handle, filename) except OTAError as err: _LOGGER.error(str(err)) return 1 finally: sock.close() file_handle.close() return 0
def test_is_ip_address__valid(value): actual = helpers.is_ip_address(value) assert actual is True
def test_is_ip_address__invalid(host): actual = helpers.is_ip_address(host) assert actual is False