Fix homematicip_cloud tests that have uncaught exceptions (#33371)
parent
42cb5a5239
commit
3c2df7f8f2
|
@ -121,9 +121,13 @@ class HomematicipGenericDevice(Entity):
|
||||||
|
|
||||||
# Only go further if the device/entity should be removed from registries
|
# Only go further if the device/entity should be removed from registries
|
||||||
# due to a removal of the HmIP device.
|
# due to a removal of the HmIP device.
|
||||||
|
|
||||||
if self.hmip_device_removed:
|
if self.hmip_device_removed:
|
||||||
|
try:
|
||||||
del self._hap.hmip_device_by_entity_id[self.entity_id]
|
del self._hap.hmip_device_by_entity_id[self.entity_id]
|
||||||
await self.async_remove_from_registries()
|
await self.async_remove_from_registries()
|
||||||
|
except KeyError as err:
|
||||||
|
_LOGGER.debug("Error removing HMIP entity from registry: %s", err)
|
||||||
|
|
||||||
async def async_remove_from_registries(self) -> None:
|
async def async_remove_from_registries(self) -> None:
|
||||||
"""Remove entity/device from registry."""
|
"""Remove entity/device from registry."""
|
||||||
|
|
|
@ -3,6 +3,7 @@ from asynctest import CoroutineMock, MagicMock, Mock, patch
|
||||||
from homematicip.aio.auth import AsyncAuth
|
from homematicip.aio.auth import AsyncAuth
|
||||||
from homematicip.aio.connection import AsyncConnection
|
from homematicip.aio.connection import AsyncConnection
|
||||||
from homematicip.aio.home import AsyncHome
|
from homematicip.aio.home import AsyncHome
|
||||||
|
from homematicip.base.enums import WeatherCondition, WeatherDayTime
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
|
@ -115,10 +116,21 @@ def simple_mock_home_fixture():
|
||||||
devices=[],
|
devices=[],
|
||||||
groups=[],
|
groups=[],
|
||||||
location=Mock(),
|
location=Mock(),
|
||||||
weather=Mock(create=True),
|
weather=Mock(
|
||||||
|
temperature=0.0,
|
||||||
|
weatherCondition=WeatherCondition.UNKNOWN,
|
||||||
|
weatherDayTime=WeatherDayTime.DAY,
|
||||||
|
minTemperature=0.0,
|
||||||
|
maxTemperature=0.0,
|
||||||
|
humidity=0,
|
||||||
|
windSpeed=0.0,
|
||||||
|
windDirection=0,
|
||||||
|
vaporAmount=0.0,
|
||||||
|
),
|
||||||
id=42,
|
id=42,
|
||||||
dutyCycle=88,
|
dutyCycle=88,
|
||||||
connected=True,
|
connected=True,
|
||||||
|
currentAPVersion="2.0.36",
|
||||||
)
|
)
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
|
|
|
@ -52,6 +52,8 @@ async def test_flow_works(hass, simple_mock_home):
|
||||||
), patch(
|
), patch(
|
||||||
"homeassistant.components.homematicip_cloud.hap.HomematicipAuth.async_register",
|
"homeassistant.components.homematicip_cloud.hap.HomematicipAuth.async_register",
|
||||||
return_value=True,
|
return_value=True,
|
||||||
|
), patch(
|
||||||
|
"homeassistant.components.homematicip_cloud.hap.HomematicipHAP.async_connect",
|
||||||
):
|
):
|
||||||
result = await hass.config_entries.flow.async_configure(
|
result = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"], user_input={}
|
result["flow_id"], user_input={}
|
||||||
|
@ -151,6 +153,8 @@ async def test_import_config(hass, simple_mock_home):
|
||||||
), patch(
|
), patch(
|
||||||
"homeassistant.components.homematicip_cloud.hap.HomematicipAuth.async_register",
|
"homeassistant.components.homematicip_cloud.hap.HomematicipAuth.async_register",
|
||||||
return_value=True,
|
return_value=True,
|
||||||
|
), patch(
|
||||||
|
"homeassistant.components.homematicip_cloud.hap.HomematicipHAP.async_connect",
|
||||||
):
|
):
|
||||||
result = await hass.config_entries.flow.async_init(
|
result = await hass.config_entries.flow.async_init(
|
||||||
HMIPC_DOMAIN, context={"source": "import"}, data=IMPORT_CONFIG
|
HMIPC_DOMAIN, context={"source": "import"}, data=IMPORT_CONFIG
|
||||||
|
|
|
@ -39,7 +39,12 @@ async def test_config_with_accesspoint_passed_to_config_entry(
|
||||||
# no acccesspoint exists
|
# no acccesspoint exists
|
||||||
assert not hass.data.get(HMIPC_DOMAIN)
|
assert not hass.data.get(HMIPC_DOMAIN)
|
||||||
|
|
||||||
assert await async_setup_component(hass, HMIPC_DOMAIN, {HMIPC_DOMAIN: entry_config})
|
with patch(
|
||||||
|
"homeassistant.components.homematicip_cloud.hap.HomematicipHAP.async_connect",
|
||||||
|
):
|
||||||
|
assert await async_setup_component(
|
||||||
|
hass, HMIPC_DOMAIN, {HMIPC_DOMAIN: entry_config}
|
||||||
|
)
|
||||||
|
|
||||||
# config_entry created for access point
|
# config_entry created for access point
|
||||||
config_entries = hass.config_entries.async_entries(HMIPC_DOMAIN)
|
config_entries = hass.config_entries.async_entries(HMIPC_DOMAIN)
|
||||||
|
@ -77,7 +82,13 @@ async def test_config_already_registered_not_passed_to_config_entry(
|
||||||
CONF_AUTHTOKEN: "123",
|
CONF_AUTHTOKEN: "123",
|
||||||
CONF_NAME: "name",
|
CONF_NAME: "name",
|
||||||
}
|
}
|
||||||
assert await async_setup_component(hass, HMIPC_DOMAIN, {HMIPC_DOMAIN: entry_config})
|
|
||||||
|
with patch(
|
||||||
|
"homeassistant.components.homematicip_cloud.hap.HomematicipHAP.async_connect",
|
||||||
|
):
|
||||||
|
assert await async_setup_component(
|
||||||
|
hass, HMIPC_DOMAIN, {HMIPC_DOMAIN: entry_config}
|
||||||
|
)
|
||||||
|
|
||||||
# no new config_entry created / still one config_entry
|
# no new config_entry created / still one config_entry
|
||||||
config_entries = hass.config_entries.async_entries(HMIPC_DOMAIN)
|
config_entries = hass.config_entries.async_entries(HMIPC_DOMAIN)
|
||||||
|
@ -107,16 +118,14 @@ async def test_load_entry_fails_due_to_connection_error(
|
||||||
assert hmip_config_entry.state == ENTRY_STATE_SETUP_RETRY
|
assert hmip_config_entry.state == ENTRY_STATE_SETUP_RETRY
|
||||||
|
|
||||||
|
|
||||||
async def test_load_entry_fails_due_to_generic_exception(
|
async def test_load_entry_fails_due_to_generic_exception(hass, hmip_config_entry):
|
||||||
hass, hmip_config_entry, simple_mock_home
|
|
||||||
):
|
|
||||||
"""Test load entry fails due to generic exception."""
|
"""Test load entry fails due to generic exception."""
|
||||||
hmip_config_entry.add_to_hass(hass)
|
hmip_config_entry.add_to_hass(hass)
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.homematicip_cloud.hap.AsyncHome.get_current_state",
|
"homeassistant.components.homematicip_cloud.hap.AsyncHome.get_current_state",
|
||||||
side_effect=Exception,
|
side_effect=Exception,
|
||||||
):
|
), patch("homematicip.aio.connection.AsyncConnection.init",):
|
||||||
assert await async_setup_component(hass, HMIPC_DOMAIN, {})
|
assert await async_setup_component(hass, HMIPC_DOMAIN, {})
|
||||||
|
|
||||||
assert hass.data[HMIPC_DOMAIN][hmip_config_entry.unique_id]
|
assert hass.data[HMIPC_DOMAIN][hmip_config_entry.unique_id]
|
||||||
|
|
|
@ -54,21 +54,6 @@ IGNORE_UNCAUGHT_EXCEPTIONS = [
|
||||||
("tests.components.geonetnz_quakes.test_geo_location", "test_setup"),
|
("tests.components.geonetnz_quakes.test_geo_location", "test_setup"),
|
||||||
("tests.components.geonetnz_quakes.test_sensor", "test_setup"),
|
("tests.components.geonetnz_quakes.test_sensor", "test_setup"),
|
||||||
("test_homeassistant_bridge", "test_homeassistant_bridge_fan_setup"),
|
("test_homeassistant_bridge", "test_homeassistant_bridge_fan_setup"),
|
||||||
("tests.components.homematicip_cloud.test_config_flow", "test_flow_works"),
|
|
||||||
("tests.components.homematicip_cloud.test_config_flow", "test_import_config"),
|
|
||||||
("tests.components.homematicip_cloud.test_device", "test_hmip_remove_group"),
|
|
||||||
(
|
|
||||||
"tests.components.homematicip_cloud.test_init",
|
|
||||||
"test_config_with_accesspoint_passed_to_config_entry",
|
|
||||||
),
|
|
||||||
(
|
|
||||||
"tests.components.homematicip_cloud.test_init",
|
|
||||||
"test_config_already_registered_not_passed_to_config_entry",
|
|
||||||
),
|
|
||||||
(
|
|
||||||
"tests.components.homematicip_cloud.test_init",
|
|
||||||
"test_load_entry_fails_due_to_generic_exception",
|
|
||||||
),
|
|
||||||
("tests.components.hue.test_bridge", "test_handle_unauthorized"),
|
("tests.components.hue.test_bridge", "test_handle_unauthorized"),
|
||||||
("tests.components.hue.test_init", "test_security_vuln_check"),
|
("tests.components.hue.test_init", "test_security_vuln_check"),
|
||||||
("tests.components.hue.test_light", "test_group_features"),
|
("tests.components.hue.test_light", "test_group_features"),
|
||||||
|
|
Loading…
Reference in New Issue