Skip to content

Commit 80bd06b

Browse files
authored
Fix saving the changed data from option flow (#137)
1 parent b668e83 commit 80bd06b

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

custom_components/ta_cmi/config_flow.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
"""Config flow for Technische Alternative C.M.I. integration."""
22
from __future__ import annotations
33

4+
import time
45
from copy import deepcopy
56
from datetime import timedelta
6-
import time
77
from typing import Any
88

9+
import homeassistant.helpers.config_validation as cv
10+
import voluptuous as vol
911
from aiohttp import ClientSession
1012
from homeassistant import config_entries
1113
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME
1214
from homeassistant.core import callback
1315
from homeassistant.data_entry_flow import FlowResult
1416
from homeassistant.exceptions import HomeAssistantError
1517
from homeassistant.helpers.aiohttp_client import async_get_clientsession
16-
import homeassistant.helpers.config_validation as cv
1718
from ta_cmi import CMI, ApiError, Device, InvalidCredentialsError, RateLimitError
18-
import voluptuous as vol
1919

2020
from . import custom_sleep
2121
from .const import (
@@ -349,9 +349,15 @@ async def async_step_init(
349349
errors["base"] = "unknown"
350350
else:
351351
self.data[CONF_HOST] = user_input[CONF_HOST]
352-
return self.async_create_entry(title="", data=self.data)
352+
self.hass.config_entries.async_update_entry(
353+
self.config_entry, data=self.data
354+
)
355+
return self.async_create_entry(title="", data={})
353356
else:
354-
return self.async_create_entry(title="", data=self.data)
357+
self.hass.config_entries.async_update_entry(
358+
self.config_entry, data=self.data
359+
)
360+
return self.async_create_entry(title="", data={})
355361

356362
return self.async_show_form(
357363
step_id="init",

tests/test_config_flow.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ async def test_options_flow_init_no_ip(hass: HomeAssistant) -> None:
572572
)
573573

574574
assert result["type"] == FlowResultType.CREATE_ENTRY
575-
assert dict(config_entry.options) == DUMMY_CONFIG_ENTRY_UPDATED
575+
assert dict(config_entry.data) == DUMMY_CONFIG_ENTRY_UPDATED
576576

577577

578578
@pytest.mark.asyncio
@@ -607,7 +607,7 @@ async def test_options_flow_init(hass: HomeAssistant) -> None:
607607
)
608608

609609
assert result["type"] == FlowResultType.CREATE_ENTRY
610-
assert dict(config_entry.options) == DUMMY_CONFIG_ENTRY_UPDATED_IP
610+
assert dict(config_entry.data) == DUMMY_CONFIG_ENTRY_UPDATED_IP
611611

612612

613613
@pytest.mark.asyncio
@@ -640,7 +640,7 @@ async def test_options_flow_ip_change_invalid_auth(hass: HomeAssistant) -> None:
640640
assert result["type"] == FlowResultType.FORM
641641
assert result["step_id"] == "init"
642642
assert result["errors"] == {"base": "invalid_auth"}
643-
assert dict(config_entry.options) == {}
643+
assert dict(config_entry.data) == DUMMY_CONFIG_ENTRY
644644

645645

646646
@pytest.mark.asyncio

0 commit comments

Comments
 (0)