Skip to content

Commit

Permalink
Fix flow
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Mamontov committed Apr 8, 2022
1 parent f7abb8f commit bec1f57
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
14 changes: 10 additions & 4 deletions custom_components/miwifi/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ async def async_step_user(
vol.Required(
CONF_SCAN_INTERVAL, default=DEFAULT_SCAN_INTERVAL
): vol.All(vol.Coerce(int), vol.Range(min=10)),
vol.Optional(
vol.Required(
CONF_TIMEOUT,
default=DEFAULT_TIMEOUT,
): vol.All(vol.Coerce(int), vol.Range(min=10)),
Expand All @@ -152,7 +152,10 @@ async def async_step_discovery_confirm(
self._abort_if_unique_id_configured()

code: codes = await async_verify_access(
self.hass, user_input[CONF_IP_ADDRESS], user_input[CONF_PASSWORD]
self.hass,
user_input[CONF_IP_ADDRESS],
user_input[CONF_PASSWORD],
user_input[CONF_TIMEOUT],
)

_LOGGER.debug("Verify access code: %s", code)
Expand Down Expand Up @@ -196,7 +199,7 @@ async def async_step_discovery_confirm(
vol.Required(
CONF_SCAN_INTERVAL, default=DEFAULT_SCAN_INTERVAL
): vol.All(vol.Coerce(int), vol.Range(min=10)),
vol.Optional(
vol.Required(
CONF_TIMEOUT,
default=DEFAULT_TIMEOUT,
): vol.All(vol.Coerce(int), vol.Range(min=10)),
Expand Down Expand Up @@ -228,7 +231,10 @@ async def async_step_init(self, user_input: ConfigType | None = None) -> FlowRes
errors: dict[str, str] = {}
if user_input is not None:
code: codes = await async_verify_access(
self.hass, user_input[CONF_IP_ADDRESS], user_input[CONF_PASSWORD]
self.hass,
user_input[CONF_IP_ADDRESS],
user_input[CONF_PASSWORD],
user_input[CONF_TIMEOUT],
)

_LOGGER.debug("Verify access code: %s", code)
Expand Down
11 changes: 8 additions & 3 deletions custom_components/miwifi/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from homeassistant.util import slugify
from httpx import codes

from .const import DOMAIN, STORAGE_VERSION
from .const import DOMAIN, STORAGE_VERSION, DEFAULT_TIMEOUT
from .updater import LuciUpdater


Expand All @@ -36,16 +36,21 @@ def get_config_value(
)


async def async_verify_access(hass: HomeAssistant, ip: str, password: str) -> codes:
async def async_verify_access(
hass: HomeAssistant, ip: str, password: str, timeout: int = DEFAULT_TIMEOUT
) -> codes:
"""Verify ip and password.
:param hass: HomeAssistant: Home Assistant object
:param ip: str: device ip address
:param password: str: device password
:param timeout: int: Timeout
:return int: last update success
"""

updater = LuciUpdater(hass=hass, ip=ip, password=password, is_only_login=True)
updater = LuciUpdater(
hass=hass, ip=ip, password=password, timeout=timeout, is_only_login=True
)

await updater.async_request_refresh()
await updater.async_stop()
Expand Down

0 comments on commit bec1f57

Please sign in to comment.