Skip to content

Commit

Permalink
Fetch new option values correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyroberts committed Dec 4, 2023
1 parent 1cfa945 commit 0b6899c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 16 deletions.
6 changes: 3 additions & 3 deletions custom_components/wundasmart/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
wunda_ip = entry.data[CONF_HOST]
wunda_user = entry.data[CONF_USERNAME]
wunda_pass = entry.data[CONF_PASSWORD]
update_interval = timedelta(seconds=entry.data.get(CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL))
connect_timeout = entry.data.get(CONF_CONNECT_TIMEOUT, DEFAULT_CONNECT_TIMEOUT)
read_timeout = entry.data.get(CONF_READ_TIMEOUT, DEFAULT_READ_TIMEOUT)
update_interval = timedelta(seconds=entry.options.get(CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL))
connect_timeout = entry.options.get(CONF_CONNECT_TIMEOUT, DEFAULT_CONNECT_TIMEOUT)
read_timeout = entry.options.get(CONF_READ_TIMEOUT, DEFAULT_READ_TIMEOUT)
timeout = aiohttp.ClientTimeout(sock_connect=connect_timeout, sock_read=read_timeout)

coordinator = WundasmartDataUpdateCoordinator(
Expand Down
4 changes: 2 additions & 2 deletions custom_components/wundasmart/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ async def async_setup_entry(
coordinator: WundasmartDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
session = aiohttp_client.async_get_clientsession(hass)

connect_timeout = entry.data.get(CONF_CONNECT_TIMEOUT, DEFAULT_CONNECT_TIMEOUT)
read_timeout = entry.data.get(CONF_READ_TIMEOUT, DEFAULT_READ_TIMEOUT)
connect_timeout = entry.options.get(CONF_CONNECT_TIMEOUT, DEFAULT_CONNECT_TIMEOUT)
read_timeout = entry.options.get(CONF_READ_TIMEOUT, DEFAULT_READ_TIMEOUT)
timeout = aiohttp.ClientTimeout(sock_connect=connect_timeout, sock_read=read_timeout)

rooms = (
Expand Down
28 changes: 19 additions & 9 deletions custom_components/wundasmart/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,6 @@
}
)

STEP_INIT_DATA_SCHEMA = vol.Schema(
{
vol.Optional(CONF_SCAN_INTERVAL, default=DEFAULT_SCAN_INTERVAL): int,
vol.Optional(CONF_CONNECT_TIMEOUT, default=DEFAULT_CONNECT_TIMEOUT): int,
vol.Optional(CONF_READ_TIMEOUT, default=DEFAULT_READ_TIMEOUT): int
}
)


class Hub:
"""Wundasmart Hub class."""
Expand Down Expand Up @@ -107,7 +99,25 @@ async def async_step_init(self, user_input: dict[str, Any] | None = None) -> Flo
if user_input is not None:
return self.async_create_entry(title="", data=user_input)

return self.async_show_form(step_id="init", data_schema=STEP_INIT_DATA_SCHEMA)
options = {
vol.Optional(
CONF_SCAN_INTERVAL,
default=self.config_entry.options.get(
CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL
)): int,
vol.Optional(
CONF_CONNECT_TIMEOUT,
default=self.config_entry.options.get(
CONF_CONNECT_TIMEOUT, DEFAULT_CONNECT_TIMEOUT
)): int,
vol.Optional(
CONF_READ_TIMEOUT,
default=self.config_entry.options.get(
CONF_READ_TIMEOUT, DEFAULT_READ_TIMEOUT
)): int
}

return self.async_show_form(step_id="init", data_schema=vol.Schema(options))


class CannotConnect(exceptions.HomeAssistantError):
Expand Down
4 changes: 2 additions & 2 deletions custom_components/wundasmart/water_heater.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ async def async_setup_entry(
coordinator: WundasmartDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
session = aiohttp_client.async_get_clientsession(hass)

connect_timeout = entry.data.get(CONF_CONNECT_TIMEOUT, DEFAULT_CONNECT_TIMEOUT)
read_timeout = entry.data.get(CONF_READ_TIMEOUT, DEFAULT_READ_TIMEOUT)
connect_timeout = entry.options.get(CONF_CONNECT_TIMEOUT, DEFAULT_CONNECT_TIMEOUT)
read_timeout = entry.options.get(CONF_READ_TIMEOUT, DEFAULT_READ_TIMEOUT)
timeout = aiohttp.ClientTimeout(sock_connect=connect_timeout, sock_read=read_timeout)

async_add_entities(
Expand Down

0 comments on commit 0b6899c

Please sign in to comment.