mirror of
https://github.com/home-assistant/core.git
synced 2025-08-21 21:42:50 +02:00
methods to functions
This commit is contained in:
@@ -26,36 +26,20 @@ RESULT_NOT_FOUND = "not_found"
|
|||||||
RESULT_NOT_SUPPORTED = "not_supported"
|
RESULT_NOT_SUPPORTED = "not_supported"
|
||||||
|
|
||||||
|
|
||||||
class SamsungTVConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
def _is_already_configured(hass, ip_address):
|
||||||
"""Handle a Samsung TV config flow."""
|
|
||||||
|
|
||||||
VERSION = 1
|
|
||||||
CONNECTION_CLASS = config_entries.CONN_CLASS_LOCAL_POLL
|
|
||||||
|
|
||||||
# pylint: disable=no-member # https://github.com/PyCQA/pylint/issues/3167
|
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
"""Initialize flow."""
|
|
||||||
self._host = None
|
|
||||||
self._ip = None
|
|
||||||
self._manufacturer = None
|
|
||||||
self._model = None
|
|
||||||
self._uuid = None
|
|
||||||
self._name = None
|
|
||||||
self._title = None
|
|
||||||
|
|
||||||
def _is_already_configured(self, ip_address):
|
|
||||||
return any(
|
return any(
|
||||||
ip_address == entry.data.get(CONF_IP_ADDRESS)
|
ip_address == entry.data.get(CONF_IP_ADDRESS)
|
||||||
for entry in self.hass.config_entries.async_entries(DOMAIN)
|
for entry in hass.config_entries.async_entries(DOMAIN)
|
||||||
)
|
)
|
||||||
|
|
||||||
def _get_ip(self, host):
|
|
||||||
|
def _get_ip(host):
|
||||||
if host is None:
|
if host is None:
|
||||||
return None
|
return None
|
||||||
return socket.gethostbyname(host)
|
return socket.gethostbyname(host)
|
||||||
|
|
||||||
def _try_connect(self, host, name):
|
|
||||||
|
def _try_connect(host, name):
|
||||||
"""Try to connect and check auth."""
|
"""Try to connect and check auth."""
|
||||||
for method in METHODS:
|
for method in METHODS:
|
||||||
config = {
|
config = {
|
||||||
@@ -84,6 +68,25 @@ class SamsungTVConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
LOGGER.debug("No working config found")
|
LOGGER.debug("No working config found")
|
||||||
return RESULT_NOT_FOUND
|
return RESULT_NOT_FOUND
|
||||||
|
|
||||||
|
|
||||||
|
class SamsungTVConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
|
"""Handle a Samsung TV config flow."""
|
||||||
|
|
||||||
|
VERSION = 1
|
||||||
|
CONNECTION_CLASS = config_entries.CONN_CLASS_LOCAL_POLL
|
||||||
|
|
||||||
|
# pylint: disable=no-member # https://github.com/PyCQA/pylint/issues/3167
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
"""Initialize flow."""
|
||||||
|
self._host = None
|
||||||
|
self._ip = None
|
||||||
|
self._manufacturer = None
|
||||||
|
self._model = None
|
||||||
|
self._uuid = None
|
||||||
|
self._name = None
|
||||||
|
self._title = None
|
||||||
|
|
||||||
def _get_entry(self):
|
def _get_entry(self):
|
||||||
return self.async_create_entry(
|
return self.async_create_entry(
|
||||||
title=self._title,
|
title=self._title,
|
||||||
@@ -101,10 +104,10 @@ class SamsungTVConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
"""Handle a flow initialized by the user."""
|
"""Handle a flow initialized by the user."""
|
||||||
if user_input is not None:
|
if user_input is not None:
|
||||||
ip_address = await self.hass.async_add_executor_job(
|
ip_address = await self.hass.async_add_executor_job(
|
||||||
self._get_ip, user_input[ATTR_HOST]
|
_get_ip, user_input[ATTR_HOST]
|
||||||
)
|
)
|
||||||
|
|
||||||
if self._is_already_configured(ip_address):
|
if _is_already_configured(self.hass, ip_address):
|
||||||
return self.async_abort(reason="already_configured")
|
return self.async_abort(reason="already_configured")
|
||||||
|
|
||||||
self._host = user_input[CONF_HOST]
|
self._host = user_input[CONF_HOST]
|
||||||
@@ -112,7 +115,7 @@ class SamsungTVConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
self._ip = self.context[CONF_IP_ADDRESS] = ip_address
|
self._ip = self.context[CONF_IP_ADDRESS] = ip_address
|
||||||
|
|
||||||
result = await self.hass.async_add_executor_job(
|
result = await self.hass.async_add_executor_job(
|
||||||
self._try_connect, self._host, self._title
|
_try_connect, self._host, self._title
|
||||||
)
|
)
|
||||||
|
|
||||||
if result != RESULT_SUCCESS:
|
if result != RESULT_SUCCESS:
|
||||||
@@ -124,7 +127,7 @@ class SamsungTVConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
async def async_step_ssdp(self, user_input=None):
|
async def async_step_ssdp(self, user_input=None):
|
||||||
"""Handle a flow initialized by discovery."""
|
"""Handle a flow initialized by discovery."""
|
||||||
ip_address = await self.hass.async_add_executor_job(
|
ip_address = await self.hass.async_add_executor_job(
|
||||||
self._get_ip, user_input[ATTR_HOST]
|
_get_ip, user_input[ATTR_HOST]
|
||||||
)
|
)
|
||||||
|
|
||||||
if any(
|
if any(
|
||||||
@@ -133,7 +136,7 @@ class SamsungTVConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
):
|
):
|
||||||
return self.async_abort(reason="already_in_progress")
|
return self.async_abort(reason="already_in_progress")
|
||||||
|
|
||||||
if self._is_already_configured(ip_address):
|
if _is_already_configured(self.hass, ip_address):
|
||||||
return self.async_abort(reason="already_configured")
|
return self.async_abort(reason="already_configured")
|
||||||
|
|
||||||
self._host = user_input[ATTR_HOST]
|
self._host = user_input[ATTR_HOST]
|
||||||
@@ -154,7 +157,7 @@ class SamsungTVConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
"""Handle user-confirmation of discovered node."""
|
"""Handle user-confirmation of discovered node."""
|
||||||
if user_input is not None:
|
if user_input is not None:
|
||||||
result = await self.hass.async_add_executor_job(
|
result = await self.hass.async_add_executor_job(
|
||||||
self._try_connect, self._host, self._name
|
_try_connect, self._host, self._name
|
||||||
)
|
)
|
||||||
|
|
||||||
if result != RESULT_SUCCESS:
|
if result != RESULT_SUCCESS:
|
||||||
|
Reference in New Issue
Block a user