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

Code before:

    await hass.async_block_till_done()

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

    assert ha_state.state == "2"
    assert ha_state.attributes[ATTR_STATE_CLASS] == SensorStateClass.TOTAL_INCREASING

    await async_manipulate_test_data(hass, hmip_device, "smokeAlarmCounter", 3)
    ha_state = hass.states.get(entity_id)
    assert ha_state.state == "3"


async def test_hmip_smoke_detector_test_counter(
    hass: HomeAssistant, default_mock_hap_factory: HomeFactory
) -> None:
    """Test HomematicipSmokeDetectorTestCounter."""
    entity_id = "sensor.rauchwarnmelder_smoke_test_counter"
    entity_name = "Rauchwarnmelder smoke_test_counter"
    device_model = "HmIP-SWSD"

    # Pre-register the entity as enabled before platform loads
    entity_registry = er.async_get(hass)
    entity_registry.async_get_or_create(
        "sensor",
        DOMAIN,
        "3014F7110000000000000018_smoke_test_counter",
        suggested_object_id="rauchwarnmelder_smoke_test_counter",
        disabled_by=None,
    )

    mock_hap = await default_mock_hap_factory.async_get_mock_hap(
        test_devices=["Rauchwarnmelder"]
    )

    await hass.async_block_till_done()

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

    assert ha_state.state == "5"
    assert ha_state.attributes[ATTR_STATE_CLASS] == SensorStateClass.TOTAL_INCREASING


Review comment (suggestion):
```suggestion
    hass: HomeAssistant,
    default_mock_hap_factory: HomeFactory,
    entity_registry: er.EntityRegistry,
) -> None:
    """Test HomematicipSmokeDetectorTestCounter."""
    entity_id = "sensor.rauchwarnmelder_smoke_test_counter"
    entity_name = "Rauchwarnmelder smoke_test_counter"
    device_model = "HmIP-SWSD"

    # Pre-register the entity as enabled before platform loads
    entity_registry.async_get_or_create(
```

Code after:
    )

    await hass.async_block_till_done()

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

    assert ha_state.state == "2"
    assert ha_state.attributes[ATTR_STATE_CLASS] == SensorStateClass.TOTAL_INCREASING

    await async_manipulate_test_data(hass, hmip_device, "smokeAlarmCounter", 3)
    ha_state = hass.states.get(entity_id)
    assert ha_state.state == "3"


async def test_hmip_smoke_detector_test_counter(
    hass: HomeAssistant,
    default_mock_hap_factory: HomeFactory,
    entity_registry: er.EntityRegistry,
) -> None:
    """Test HomematicipSmokeDetectorTestCounter."""
    entity_id = "sensor.rauchwarnmelder_smoke_test_counter"
    entity_name = "Rauchwarnmelder smoke_test_counter"
    device_model = "HmIP-SWSD"

    # Pre-register the entity as enabled before platform loads
    entity_registry.async_get_or_create(
        "sensor",
        DOMAIN,
        "3014F7110000000000000018_smoke_test_counter",
        suggested_object_id="rauchwarnmelder_smoke_test_counter",
        disabled_by=None,
    )

    mock_hap = await default_mock_hap_factory.async_get_mock_hap(
        test_devices=["Rauchwarnmelder"]
    )

    await hass.async_block_till_done()

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

    assert ha_state.state == "5"
    assert ha_state.attributes[ATTR_STATE_CLASS] == SensorStateClass.TOTAL_INCREASING