Remove ipaddress check in AndroidTV config flow (#68630)

This commit is contained in:
ollo69
2022-03-29 10:44:33 +02:00
committed by GitHub
parent 88780b4c87
commit 0d8736b82b
2 changed files with 40 additions and 81 deletions

View File

@@ -2,7 +2,6 @@
import json
import logging
import os
import socket
from androidtv import state_detection_rules_validator
import voluptuous as vol
@@ -58,14 +57,6 @@ def _is_file(value):
return os.path.isfile(file_in) and os.access(file_in, os.R_OK)
def _get_ip(host):
"""Get the ip address from the host name."""
try:
return socket.gethostbyname(host)
except socket.gaierror:
return None
class AndroidTVFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
"""Handle a config flow."""
@@ -137,24 +128,17 @@ class AndroidTVFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
if user_input is not None:
host = user_input[CONF_HOST]
adb_key = user_input.get(CONF_ADBKEY)
adb_server = user_input.get(CONF_ADB_SERVER_IP)
if adb_key and adb_server:
return self._show_setup_form(user_input, "key_and_server")
if CONF_ADB_SERVER_IP in user_input:
if adb_key:
return self._show_setup_form(user_input, "key_and_server")
else:
user_input.pop(CONF_ADB_SERVER_PORT, None)
if adb_key:
isfile = await self.hass.async_add_executor_job(_is_file, adb_key)
if not isfile:
if not await self.hass.async_add_executor_job(_is_file, adb_key):
return self._show_setup_form(user_input, "adbkey_not_file")
ip_address = await self.hass.async_add_executor_job(_get_ip, host)
if not ip_address:
return self._show_setup_form(user_input, "invalid_host")
self._async_abort_entries_match({CONF_HOST: host})
if ip_address != host:
self._async_abort_entries_match({CONF_HOST: ip_address})
error, unique_id = await self._async_check_connection(user_input)
if error is None:
if not unique_id: