Add test for adding a device to HomematicIP Cloud (#31224)

* Add test for adding a hmip device

* refactor get_mock_hap to use config_entry setup

* remove unused parameters
This commit is contained in:
SukramJ authored and Martin Hjelmare committed 2020-01-28 08:44:30 +01:00
1 parent 9d8b4de09c
commit ec2d378a19
3 files changed
+66 -22

No files matched your search

@@ -1,9 +1,14 @@
"""Common tests for HomematicIP devices."""
from asynctest import patch
from homematicip.base.enums import EventType
from homeassistant.components.homematicip_cloud import DOMAIN as HMIPC_DOMAIN
from homeassistant.components.homematicip_cloud.hap import HomematicipHAP
from homeassistant.const import STATE_ON, STATE_UNAVAILABLE
from homeassistant.helpers import device_registry as dr, entity_registry as er
from .conftest import get_mock_hap
from .helper import async_manipulate_test_data, get_and_check_entity_basics
from .helper import HAPID, async_manipulate_test_data, get_and_check_entity_basics
async def test_hmip_remove_device(hass, default_mock_hap):
@@ -35,6 +40,51 @@ async def test_hmip_remove_device(hass, default_mock_hap):
assert len(default_mock_hap.hmip_device_by_entity_id) == pre_mapping_count - 3
async def test_hmip_add_device(hass, default_mock_hap, hmip_config_entry):
"""Test Remove of hmip device."""
entity_id = "light.treppe"
entity_name = "Treppe"
device_model = "HmIP-BSL"
ha_state, hmip_device = get_and_check_entity_basics(
hass, default_mock_hap, entity_id, entity_name, device_model
)
assert ha_state.state == STATE_ON
assert hmip_device
device_registry = await dr.async_get_registry(hass)
entity_registry = await er.async_get_registry(hass)
pre_device_count = len(device_registry.devices)
pre_entity_count = len(entity_registry.entities)
pre_mapping_count = len(default_mock_hap.hmip_device_by_entity_id)
hmip_device.fire_remove_event()
await hass.async_block_till_done()
assert len(device_registry.devices) == pre_device_count - 1
assert len(entity_registry.entities) == pre_entity_count - 3
assert len(default_mock_hap.hmip_device_by_entity_id) == pre_mapping_count - 3
reloaded_hap = HomematicipHAP(hass, hmip_config_entry)
with patch(
"homeassistant.components.homematicip_cloud.HomematicipHAP",
return_value=reloaded_hap,
), patch.object(reloaded_hap, "async_connect"), patch.object(
reloaded_hap, "get_hap", return_value=default_mock_hap.home
), patch(
"homeassistant.components.homematicip_cloud.hap.asyncio.sleep"
):
default_mock_hap.home.fire_create_event(event_type=EventType.DEVICE_ADDED)
await hass.async_block_till_done()
assert len(device_registry.devices) == pre_device_count
assert len(entity_registry.entities) == pre_entity_count
new_hap = hass.data[HMIPC_DOMAIN][HAPID]
assert len(new_hap.hmip_device_by_entity_id) == pre_mapping_count
async def test_hmip_remove_group(hass, default_mock_hap):
"""Test Remove of hmip group."""
entity_id = "switch.strom_group"
@@ -56,7 +106,6 @@ async def test_hmip_remove_group(hass, default_mock_hap):
pre_mapping_count = len(default_mock_hap.hmip_device_by_entity_id)
hmip_device.fire_remove_event()
await hass.async_block_till_done()
assert len(device_registry.devices) == pre_device_count