1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-25 05:26:47 +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

@@ -23,11 +23,9 @@ MOCK_PYHS100 = MockDependency("pyHS100")
async def test_creating_entry_tries_discover(hass):
"""Test setting up does discovery."""
with MOCK_PYHS100, patch(
"homeassistant.components.tplink.async_setup_entry",
return_value=mock_coro(True),
) as mock_setup, patch(
"pyHS100.Discover.discover", return_value={"host": 1234}
):
"homeassistant.components.tplink.async_setup_entry",
return_value=mock_coro(True),
) as mock_setup, patch("pyHS100.Discover.discover", return_value={"host": 1234}):
result = await hass.config_entries.flow.async_init(
tplink.DOMAIN, context={"source": config_entries.SOURCE_USER}
)
@@ -35,9 +33,7 @@ async def test_creating_entry_tries_discover(hass):
# Confirmation form
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
result = await hass.config_entries.flow.async_configure(
result["flow_id"], {}
)
result = await hass.config_entries.flow.async_configure(result["flow_id"], {})
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
await hass.async_block_till_done()
@@ -66,11 +62,10 @@ async def test_configuring_tplink_causes_discovery(hass):
async def test_configuring_device_types(hass, name, cls, platform, count):
"""Test that light or switch platform list is filled correctly."""
with patch("pyHS100.Discover.discover") as discover, patch(
"pyHS100.SmartDevice._query_helper"
"pyHS100.SmartDevice._query_helper"
):
discovery_data = {
"123.123.123.{}".format(c): cls("123.123.123.123")
for c in range(count)
"123.123.123.{}".format(c): cls("123.123.123.123") for c in range(count)
}
discover.return_value = discovery_data
await async_setup_component(hass, tplink.DOMAIN, {tplink.DOMAIN: {}})
@@ -110,12 +105,10 @@ class UnknownSmartDevice(SmartDevice):
async def test_configuring_devices_from_multiple_sources(hass):
"""Test static and discover devices are not duplicated."""
with patch("pyHS100.Discover.discover") as discover, patch(
"pyHS100.SmartDevice._query_helper"
"pyHS100.SmartDevice._query_helper"
):
discover_device_fail = SmartPlug("123.123.123.123")
discover_device_fail.get_sysinfo = MagicMock(
side_effect=SmartDeviceException()
)
discover_device_fail.get_sysinfo = MagicMock(side_effect=SmartDeviceException())
discover.return_value = {
"123.123.123.1": SmartBulb("123.123.123.1"),
@@ -123,22 +116,20 @@ async def test_configuring_devices_from_multiple_sources(hass):
"123.123.123.3": SmartBulb("123.123.123.3"),
"123.123.123.4": SmartPlug("123.123.123.4"),
"123.123.123.123": discover_device_fail,
"123.123.123.124": UnknownSmartDevice("123.123.123.124")
"123.123.123.124": UnknownSmartDevice("123.123.123.124"),
}
await async_setup_component(hass, tplink.DOMAIN, {
tplink.DOMAIN: {
CONF_LIGHT: [
{CONF_HOST: "123.123.123.1"},
],
CONF_SWITCH: [
{CONF_HOST: "123.123.123.2"},
],
CONF_DIMMER: [
{CONF_HOST: "123.123.123.22"},
],
}
})
await async_setup_component(
hass,
tplink.DOMAIN,
{
tplink.DOMAIN: {
CONF_LIGHT: [{CONF_HOST: "123.123.123.1"}],
CONF_SWITCH: [{CONF_HOST: "123.123.123.2"}],
CONF_DIMMER: [{CONF_HOST: "123.123.123.22"}],
}
},
)
await hass.async_block_till_done()
assert len(discover.mock_calls) == 1
@@ -149,8 +140,8 @@ async def test_configuring_devices_from_multiple_sources(hass):
async def test_is_dimmable(hass):
"""Test that is_dimmable switches are correctly added as lights."""
with patch("pyHS100.Discover.discover") as discover, patch(
"homeassistant.components.tplink.light.async_setup_entry",
return_value=mock_coro(True),
"homeassistant.components.tplink.light.async_setup_entry",
return_value=mock_coro(True),
) as setup, patch("pyHS100.SmartDevice._query_helper"), patch(
"pyHS100.SmartPlug.is_dimmable", True
):
@@ -169,15 +160,11 @@ async def test_is_dimmable(hass):
async def test_configuring_discovery_disabled(hass):
"""Test that discover does not get called when disabled."""
with MOCK_PYHS100, patch(
"homeassistant.components.tplink.async_setup_entry",
return_value=mock_coro(True),
) as mock_setup, patch(
"pyHS100.Discover.discover", return_value=[]
) as discover:
"homeassistant.components.tplink.async_setup_entry",
return_value=mock_coro(True),
) as mock_setup, patch("pyHS100.Discover.discover", return_value=[]) as discover:
await async_setup_component(
hass,
tplink.DOMAIN,
{tplink.DOMAIN: {tplink.CONF_DISCOVERY: False}},
hass, tplink.DOMAIN, {tplink.DOMAIN: {tplink.CONF_DISCOVERY: False}}
)
await hass.async_block_till_done()
@@ -196,7 +183,7 @@ async def test_platforms_are_initialized(hass):
}
with patch("pyHS100.Discover.discover") as discover, patch(
"pyHS100.SmartDevice._query_helper"
"pyHS100.SmartDevice._query_helper"
), patch(
"homeassistant.components.tplink.light.async_setup_entry",
return_value=mock_coro(True),
@@ -218,8 +205,8 @@ async def test_platforms_are_initialized(hass):
async def test_no_config_creates_no_entry(hass):
"""Test for when there is no tplink in config."""
with MOCK_PYHS100, patch(
"homeassistant.components.tplink.async_setup_entry",
return_value=mock_coro(True),
"homeassistant.components.tplink.async_setup_entry",
return_value=mock_coro(True),
) as mock_setup:
await async_setup_component(hass, tplink.DOMAIN, {})
await hass.async_block_till_done()
@@ -235,9 +222,8 @@ async def test_unload(hass, platform):
entry.add_to_hass(hass)
with patch("pyHS100.SmartDevice._query_helper"), patch(
"homeassistant.components.tplink.{}"
".async_setup_entry".format(platform),
return_value=mock_coro(True),
"homeassistant.components.tplink.{}" ".async_setup_entry".format(platform),
return_value=mock_coro(True),
) as light_setup:
config = {
tplink.DOMAIN: {