Repository: home-assistant/core
File: tests/components/homematicip_cloud/test_device.py (Python)

Code before:
"""Common tests for HomematicIP devices."""

from unittest.mock import patch

from homematicip.base.enums import EventType

from homeassistant.components.homematicip_cloud.hap import HomematicipHAP
from homeassistant.const import STATE_ON, STATE_UNAVAILABLE
from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry as dr, entity_registry as er

from .helper import HomeFactory, async_manipulate_test_data, get_and_check_entity_basics

from tests.common import MockConfigEntry


async def test_hmip_load_all_supported_devices(
    hass: HomeAssistant, default_mock_hap_factory: HomeFactory
) -> None:
    """Ensure that all supported devices could be loaded."""
    mock_hap = await default_mock_hap_factory.async_get_mock_hap(
        test_devices=None, test_groups=None
    )

    assert len(mock_hap.hmip_device_by_entity_id) == 349


async def test_hmip_remove_device(
    hass: HomeAssistant,
    entity_registry: er.EntityRegistry,
    device_registry: dr.DeviceRegistry,
    default_mock_hap_factory: HomeFactory,
) -> None:
    """Test Remove of hmip device."""
    entity_id = "light.treppe_ch"
    entity_name = "Treppe CH"
    device_model = "HmIP-BSL"
    mock_hap = await default_mock_hap_factory.async_get_mock_hap(
        test_devices=["Treppe"]
    )

    ha_state, hmip_device = get_and_check_entity_basics(
        hass, mock_hap, entity_id, entity_name, device_model
    )

    assert ha_state.state == STATE_ON
    assert hmip_device

    pre_device_count = len(device_registry.devices)
    pre_entity_count = len(entity_registry.entities)

Review comment (suggestion):
```suggestion
    assert len(mock_hap.hmip_device_by_entity_id) == 350
```

Code after:
"""Common tests for HomematicIP devices."""

from unittest.mock import patch

from homematicip.base.enums import EventType

from homeassistant.components.homematicip_cloud.hap import HomematicipHAP
from homeassistant.const import STATE_ON, STATE_UNAVAILABLE
from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry as dr, entity_registry as er

from .helper import HomeFactory, async_manipulate_test_data, get_and_check_entity_basics

from tests.common import MockConfigEntry


async def test_hmip_load_all_supported_devices(
    hass: HomeAssistant, default_mock_hap_factory: HomeFactory
) -> None:
    """Ensure that all supported devices could be loaded."""
    mock_hap = await default_mock_hap_factory.async_get_mock_hap(
        test_devices=None, test_groups=None
    )

    assert len(mock_hap.hmip_device_by_entity_id) == 350


async def test_hmip_remove_device(
    hass: HomeAssistant,
    entity_registry: er.EntityRegistry,
    device_registry: dr.DeviceRegistry,
    default_mock_hap_factory: HomeFactory,
) -> None:
    """Test Remove of hmip device."""
    entity_id = "light.treppe_ch"
    entity_name = "Treppe CH"
    device_model = "HmIP-BSL"
    mock_hap = await default_mock_hap_factory.async_get_mock_hap(
        test_devices=["Treppe"]
    )

    ha_state, hmip_device = get_and_check_entity_basics(
        hass, mock_hap, entity_id, entity_name, device_model
    )

    assert ha_state.state == STATE_ON
    assert hmip_device

    pre_device_count = len(device_registry.devices)
    pre_entity_count = len(entity_registry.entities)