1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +00:00
This commit is contained in:
Paulus Schoutsen
2019-07-31 12:25:30 -07:00
parent da05dfe708
commit 4de97abc3a
2676 changed files with 163166 additions and 140084 deletions

View File

@@ -9,8 +9,9 @@ from tests.common import mock_coro, MockConfigEntry
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=[]):
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
# No flows started
@@ -22,100 +23,121 @@ 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']):
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
}
}
}) is True
with patch.object(hass, "config_entries") as mock_config_entries, patch.object(
hue, "configured_hosts", return_value=["0.0.0.0"]
):
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,
}
}
},
)
is True
)
# Flow started for discovered bridge
assert len(mock_config_entries.flow.mock_calls) == 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',
"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
hue.CONF_ALLOW_UNREACHABLE: True,
}
}
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=[]):
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
}
}
}) is True
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,
}
}
},
)
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 mock_config_entries.flow.mock_calls[0][2]["data"] == {
"host": "0.0.0.0",
"path": "bla.conf",
}
# 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',
"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
hue.CONF_ALLOW_UNREACHABLE: True,
}
}
async def test_config_passed_to_config_entry(hass):
"""Test that configured options for a host are loaded via config entry."""
entry = MockConfigEntry(domain=hue.DOMAIN, data={
'host': '0.0.0.0',
})
entry = MockConfigEntry(domain=hue.DOMAIN, data={"host": "0.0.0.0"})
entry.add_to_hass(hass)
mock_registry = Mock()
with patch.object(hue, 'HueBridge') as mock_bridge, \
patch('homeassistant.helpers.device_registry.async_get_registry',
return_value=mock_coro(mock_registry)):
with patch.object(hue, "HueBridge") as mock_bridge, patch(
"homeassistant.helpers.device_registry.async_get_registry",
return_value=mock_coro(mock_registry),
):
mock_bridge.return_value.async_setup.return_value = mock_coro(True)
mock_bridge.return_value.api.config = Mock(
mac='mock-mac',
bridgeid='mock-bridgeid',
modelid='mock-modelid',
swversion='mock-swversion'
mac="mock-mac",
bridgeid="mock-bridgeid",
modelid="mock-modelid",
swversion="mock-swversion",
)
# Can't set name via kwargs
mock_bridge.return_value.api.config.name = 'mock-name'
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
}
}
}) is True
mock_bridge.return_value.api.config.name = "mock-name"
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,
}
}
},
)
is True
)
assert len(mock_bridge.mock_calls) == 2
p_hass, p_entry, p_allow_unreachable, p_allow_groups = \
mock_bridge.mock_calls[0][1]
p_hass, p_entry, p_allow_unreachable, p_allow_groups = mock_bridge.mock_calls[0][1]
assert p_hass is hass
assert p_entry is entry
@@ -124,30 +146,25 @@ async def test_config_passed_to_config_entry(hass):
assert len(mock_registry.mock_calls) == 1
assert mock_registry.mock_calls[0][2] == {
'config_entry_id': entry.entry_id,
'connections': {
('mac', 'mock-mac')
},
'identifiers': {
('hue', 'mock-bridgeid')
},
'manufacturer': 'Signify',
'name': 'mock-name',
'model': 'mock-modelid',
'sw_version': 'mock-swversion',
"config_entry_id": entry.entry_id,
"connections": {("mac", "mock-mac")},
"identifiers": {("hue", "mock-bridgeid")},
"manufacturer": "Signify",
"name": "mock-name",
"model": "mock-modelid",
"sw_version": "mock-swversion",
}
async def test_unload_entry(hass):
"""Test being able to unload an entry."""
entry = MockConfigEntry(domain=hue.DOMAIN, data={
'host': '0.0.0.0',
})
entry = MockConfigEntry(domain=hue.DOMAIN, data={"host": "0.0.0.0"})
entry.add_to_hass(hass)
with patch.object(hue, 'HueBridge') as mock_bridge, \
patch('homeassistant.helpers.device_registry.async_get_registry',
return_value=mock_coro(Mock())):
with patch.object(hue, "HueBridge") as mock_bridge, patch(
"homeassistant.helpers.device_registry.async_get_registry",
return_value=mock_coro(Mock()),
):
mock_bridge.return_value.async_setup.return_value = mock_coro(True)
mock_bridge.return_value.api.config = Mock()
assert await async_setup_component(hass, hue.DOMAIN, {}) is True