Repository: home-assistant/core
File: tests/components/intent/test_timers.py (Python)

Code before:
) -> None:
    """Test starting a timer with an invalid conversation command fails validation."""
    device_id = "test_device"
    timer_name = "test timer"
    invalid_command = "invalid command that does not exist"
    agent_id = None  # Default agent

    mock_handle_timer = MagicMock()
    async_register_timer_handler(hass, device_id, mock_handle_timer)

    with pytest.raises(NoTimerCommandError):
        await intent.async_handle(
            hass,
            "test",
            intent.INTENT_START_TIMER,
            {
                "name": {"value": timer_name},
                "seconds": {"value": 5},
                "conversation_command": {"value": invalid_command},
            },
            device_id=device_id,
            conversation_agent_id=agent_id,
        )

    # Verify no timer was created
    mock_handle_timer.assert_not_called()


async def test_start_timer_with_conversation_command_skip_validation(
    hass: HomeAssistant, init_components
) -> None:
    """Test starting a timer with a conversation command skips validation for non-default agents."""
    device_id = "test_device"
    timer_name = "test timer"
    invalid_command = "invalid command that does not exist"
    agent_id = "conversation.test_llm_agent"

    # This should NOT raise an error because validation is skipped for all non-default agents
    result = await intent.async_handle(
        hass,
        "test",
        intent.INTENT_START_TIMER,
        {
            "name": {"value": timer_name},
            "seconds": {"value": 5},
            "conversation_command": {"value": invalid_command},
        },
        device_id=device_id,
        conversation_agent_id=agent_id,
    )


Review comment (suggestion):
```suggestion
    timer_manager = hass.data[TIMER_DATA]
    assert len(timer_manager.timers) == 0
```

Code after:
            intent.INTENT_START_TIMER,
            {
                "name": {"value": timer_name},
                "seconds": {"value": 5},
                "conversation_command": {"value": invalid_command},
            },
            device_id=device_id,
            conversation_agent_id=agent_id,
        )

    # Verify no timer was created
    timer_manager = hass.data[TIMER_DATA]
    assert len(timer_manager.timers) == 0


async def test_start_timer_with_conversation_command_skip_validation(
    hass: HomeAssistant, init_components
) -> None:
    """Test starting a timer with a conversation command skips validation for non-default agents."""
    device_id = "test_device"
    timer_name = "test timer"
    invalid_command = "invalid command that does not exist"
    agent_id = "conversation.test_llm_agent"

    # This should NOT raise an error because validation is skipped for all non-default agents
    result = await intent.async_handle(
        hass,
        "test",
        intent.INTENT_START_TIMER,
        {
            "name": {"value": timer_name},
            "seconds": {"value": 5},
            "conversation_command": {"value": invalid_command},
        },
        device_id=device_id,
        conversation_agent_id=agent_id,
    )

    assert result.response_type == intent.IntentResponseType.ACTION_DONE

    # Verify timer was created successfully despite invalid command
    timer_manager = hass.data[TIMER_DATA]
    assert len(timer_manager.timers) == 1


async def test_pause_unpause_timer_disambiguate(
    hass: HomeAssistant, init_components
) -> None:
    """Test disamgibuating timers by their paused state."""
    device_id = "test_device"
    started_timer_ids: list[str] = []