Dynalite listener for config entry update (#32116)
* added entry listener that reloads the component * fixed update with existing entry * fixed import in test * fixes * library version * removed unique_id * fix * fixed for no entries in hass.data * fixed return value on abort * moved to use async_entries * removed unused import
This commit is contained in:
9 files changed
+54
-20
No files matched your search
Executable
+9
@@ -0,0 +1,9 @@
|
||||
"""Common functions for the Dynalite tests."""
|
||||
|
||||
from homeassistant.components import dynalite
|
||||
|
||||
|
||||
def get_bridge_from_hass(hass_obj):
|
||||
"""Get the bridge from hass.data."""
|
||||
key = next(iter(hass_obj.data[dynalite.DOMAIN]))
|
||||
return hass_obj.data[dynalite.DOMAIN][key]
|
||||
@@ -2,7 +2,7 @@
|
||||
from unittest.mock import Mock, call
|
||||
|
||||
from asynctest import patch
|
||||
from dynalite_lib import CONF_ALL
|
||||
from dynalite_devices_lib import CONF_ALL
|
||||
import pytest
|
||||
|
||||
from homeassistant.components import dynalite
|
||||
|
||||
@@ -4,6 +4,8 @@ from asynctest import patch
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components import dynalite
|
||||
|
||||
from .common import get_bridge_from_hass
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
@@ -70,21 +72,29 @@ async def test_existing(hass):
|
||||
async def test_existing_update(hass):
|
||||
"""Test when the entry exists with the same config."""
|
||||
host = "1.2.3.4"
|
||||
mock_entry = MockConfigEntry(
|
||||
domain=dynalite.DOMAIN, unique_id=host, data={dynalite.CONF_HOST: host}
|
||||
)
|
||||
mock_entry.add_to_hass(hass)
|
||||
port1 = 7777
|
||||
port2 = 8888
|
||||
with patch(
|
||||
"homeassistant.components.dynalite.bridge.DynaliteDevices.async_setup",
|
||||
return_value=True,
|
||||
), patch(
|
||||
"homeassistant.components.dynalite.bridge.DynaliteDevices.available", True
|
||||
):
|
||||
assert await hass.config_entries.flow.async_init(
|
||||
dynalite.DOMAIN,
|
||||
context={"source": config_entries.SOURCE_IMPORT},
|
||||
data={dynalite.CONF_HOST: host, dynalite.CONF_PORT: port1},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
old_bridge = get_bridge_from_hass(hass)
|
||||
assert old_bridge.dynalite_devices.port == port1
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
dynalite.DOMAIN,
|
||||
context={"source": config_entries.SOURCE_IMPORT},
|
||||
data={dynalite.CONF_HOST: host, "aaa": "bbb"},
|
||||
data={dynalite.CONF_HOST: host, dynalite.CONF_PORT: port2},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert result["type"] == "abort"
|
||||
assert result["reason"] == "already_configured"
|
||||
assert mock_entry.data.get("aaa") == "bbb"
|
||||
bridge = get_bridge_from_hass(hass)
|
||||
assert bridge.dynalite_devices.port == port2
|
||||
Reference in new issue
Block a user