Convert Hue to use unique ID (#30000)
* Convert Hue to use unique ID * Fix normalization * Store/restore unique ID * Fix tests
This commit is contained in:
1 parent
575eb48feb
commit
58b5833d64
12 files changed
+385
-440
No files matched your search
@@ -9,13 +9,10 @@ from tests.common import MockConfigEntry, mock_coro
|
||||
|
||||
async def test_setup_with_no_config(hass):
|
||||
"""Test that we do not discover anything or try to set up a bridge."""
|
||||
with patch.object(hass, "config_entries") as mock_config_entries, patch.object(
|
||||
hue, "configured_hosts", return_value=[]
|
||||
):
|
||||
assert await async_setup_component(hass, hue.DOMAIN, {}) is True
|
||||
assert await async_setup_component(hass, hue.DOMAIN, {}) is True
|
||||
|
||||
# No flows started
|
||||
assert len(mock_config_entries.flow.mock_calls) == 0
|
||||
assert len(hass.config_entries.flow.async_progress()) == 0
|
||||
|
||||
# No configs stored
|
||||
assert hass.data[hue.DOMAIN] == {}
|
||||
@@ -23,9 +20,9 @@ async def test_setup_with_no_config(hass):
|
||||
|
||||
async def test_setup_defined_hosts_known_auth(hass):
|
||||
"""Test we don't initiate a config entry if config bridge is known."""
|
||||
with patch.object(hass, "config_entries") as mock_config_entries, patch.object(
|
||||
hue, "configured_hosts", return_value=["0.0.0.0"]
|
||||
):
|
||||
MockConfigEntry(domain="hue", data={"host": "0.0.0.0"}).add_to_hass(hass)
|
||||
|
||||
with patch.object(hue, "async_setup_entry", return_value=mock_coro(True)):
|
||||
assert (
|
||||
await async_setup_component(
|
||||
hass,
|
||||
@@ -34,7 +31,6 @@ async def test_setup_defined_hosts_known_auth(hass):
|
||||
hue.DOMAIN: {
|
||||
hue.CONF_BRIDGES: {
|
||||
hue.CONF_HOST: "0.0.0.0",
|
||||
hue.CONF_FILENAME: "bla.conf",
|
||||
hue.CONF_ALLOW_HUE_GROUPS: False,
|
||||
hue.CONF_ALLOW_UNREACHABLE: True,
|
||||
}
|
||||
@@ -45,13 +41,12 @@ async def test_setup_defined_hosts_known_auth(hass):
|
||||
)
|
||||
|
||||
# Flow started for discovered bridge
|
||||
assert len(mock_config_entries.flow.mock_calls) == 0
|
||||
assert len(hass.config_entries.flow.async_progress()) == 0
|
||||
|
||||
# Config stored for domain.
|
||||
assert hass.data[hue.DATA_CONFIGS] == {
|
||||
"0.0.0.0": {
|
||||
hue.CONF_HOST: "0.0.0.0",
|
||||
hue.CONF_FILENAME: "bla.conf",
|
||||
hue.CONF_ALLOW_HUE_GROUPS: False,
|
||||
hue.CONF_ALLOW_UNREACHABLE: True,
|
||||
}
|
||||
@@ -60,40 +55,30 @@ async def test_setup_defined_hosts_known_auth(hass):
|
||||
|
||||
async def test_setup_defined_hosts_no_known_auth(hass):
|
||||
"""Test we initiate config entry if config bridge is not known."""
|
||||
with patch.object(hass, "config_entries") as mock_config_entries, patch.object(
|
||||
hue, "configured_hosts", return_value=[]
|
||||
):
|
||||
mock_config_entries.flow.async_init.return_value = mock_coro()
|
||||
assert (
|
||||
await async_setup_component(
|
||||
hass,
|
||||
hue.DOMAIN,
|
||||
{
|
||||
hue.DOMAIN: {
|
||||
hue.CONF_BRIDGES: {
|
||||
hue.CONF_HOST: "0.0.0.0",
|
||||
hue.CONF_FILENAME: "bla.conf",
|
||||
hue.CONF_ALLOW_HUE_GROUPS: False,
|
||||
hue.CONF_ALLOW_UNREACHABLE: True,
|
||||
}
|
||||
assert (
|
||||
await async_setup_component(
|
||||
hass,
|
||||
hue.DOMAIN,
|
||||
{
|
||||
hue.DOMAIN: {
|
||||
hue.CONF_BRIDGES: {
|
||||
hue.CONF_HOST: "0.0.0.0",
|
||||
hue.CONF_ALLOW_HUE_GROUPS: False,
|
||||
hue.CONF_ALLOW_UNREACHABLE: True,
|
||||
}
|
||||
},
|
||||
)
|
||||
is True
|
||||
}
|
||||
},
|
||||
)
|
||||
is True
|
||||
)
|
||||
|
||||
# Flow started for discovered bridge
|
||||
assert len(mock_config_entries.flow.mock_calls) == 1
|
||||
assert mock_config_entries.flow.mock_calls[0][2]["data"] == {
|
||||
"host": "0.0.0.0",
|
||||
"path": "bla.conf",
|
||||
}
|
||||
assert len(hass.config_entries.flow.async_progress()) == 1
|
||||
|
||||
# Config stored for domain.
|
||||
assert hass.data[hue.DATA_CONFIGS] == {
|
||||
"0.0.0.0": {
|
||||
hue.CONF_HOST: "0.0.0.0",
|
||||
hue.CONF_FILENAME: "bla.conf",
|
||||
hue.CONF_ALLOW_HUE_GROUPS: False,
|
||||
hue.CONF_ALLOW_UNREACHABLE: True,
|
||||
}
|
||||
@@ -126,7 +111,6 @@ async def test_config_passed_to_config_entry(hass):
|
||||
hue.DOMAIN: {
|
||||
hue.CONF_BRIDGES: {
|
||||
hue.CONF_HOST: "0.0.0.0",
|
||||
hue.CONF_FILENAME: "bla.conf",
|
||||
hue.CONF_ALLOW_HUE_GROUPS: False,
|
||||
hue.CONF_ALLOW_UNREACHABLE: True,
|
||||
}
|
||||
@@ -166,7 +150,7 @@ async def test_unload_entry(hass):
|
||||
return_value=mock_coro(Mock()),
|
||||
):
|
||||
mock_bridge.return_value.async_setup.return_value = mock_coro(True)
|
||||
mock_bridge.return_value.api.config = Mock()
|
||||
mock_bridge.return_value.api.config = Mock(bridgeid="aabbccddeeff")
|
||||
assert await async_setup_component(hass, hue.DOMAIN, {}) is True
|
||||
|
||||
assert len(mock_bridge.return_value.mock_calls) == 1
|
||||
|
||||
Reference in new issue
Block a user