False alarm in Neyman-Pearson Test. A doubt in text?

Neyman-Pearson Lemma says that the most powerful test, $\phi(x)$, of size $\alpha$ (probability of false alarm), for testing $H_0:\theta=\theta_0$ versus $H_1:\theta=\theta_1$ is the likelihood ratio test of the form:

$$\phi(x)=\begin{cases} 1 & l(x)>k \\ \color{#C00}{p} & l(x)=k \\ 0 & l(x)<k \\ \end{cases}$$

where, $p$ is the probability of accepting $H_1$ at $k.$

$k$ is threshold.

$l(x)$ is the likelihood ratio, $l(x)=\frac{f_{\theta_1}(x)}{f_{\theta_0}(x)}.$

Probability of false alarm, $P_f=\color{#C00}{p} \cdot P[l(x)=k \hspace{2 mm}| \hspace{2 mm} H_0 ]\hspace{2 mm}+\hspace{2 mm} P[l(x)>k \hspace{2 mm}| \hspace{2 mm} H_0 ].$

Probability of detection, $P_d=p \cdot P[l(x)=k \hspace{2 mm}| \hspace{2 mm} H_1 ]\hspace{2 mm}+\hspace{2 mm} P[l(x)>k \hspace{2 mm}| \hspace{2 mm} H_1 ].$

Question Why Probability of false alarm, $P_f$, is $\mathbf{not}$ defined as:

$P_f=\color{#C00}{(1-p)} \cdot P[l(x)=k \hspace{2 mm}| \hspace{2 mm} H_0 ]\hspace{2 mm}+\hspace{2 mm} P[l(x)>k \hspace{2 mm}| \hspace{2 mm} H_0 ].$

My understanding for saying above equation is that: if the probability of occurring $H_1$ is $p$, then the probability of occurring $H_0$ is $(1-p).$ And therefore, the probability of selecting $H_0$ at $k$ is $(1-p).P[l(x)=k \hspace{2 mm}| \hspace{2 mm} H_0].$

Where my understanding is wrong? Any comments please.

I am not sure what you mean by 'probability of occurring $H_0$', but that might be where you are confused. Note that $H_1$ and $H_0$ are not treated as random events and thus they have no probability. Instead, we assume either that $H_1$ is true or that $H_0$ is true, and compute probabilities of random events given $H_0$ or given $H_1$.

False alarm is defined as rejecting $H_0$ (accepting $H_1$) while $H_0$ is actually true. 'Probability of false alarm' in this context means the probability of false alarm given that $H_0$ is true. That is, $$P[\textrm{We accept }H_1 \mid H_0].$$ We can divide this probability into 3 separate events depending on whether $l(x)<k,l(x)=k,l(x)>k$: $$=P[\textrm{We accept }H_1 \cap l(x)<k \mid H_0] + P[\textrm{We accept }H_1 \cap l(x)=k \mid H_0] + P[\textrm{We accept }H_1 \cap l(x)>k \mid H_0]$$ The first term is obviously $0$ as we never accept $H_1$ when $l(x)<k$. The third term is just $P[l(x)>k \mid H_0]$ as $H_0$ is always accepted when $l(x)>k$. For the second term, $$P[\textrm{We accept }H_1 \cap l(x) = k \mid H_0] = P[\textrm{We accept }H_1 \mid l(x)=k, H_0]P[l(x)=k \mid H_0] = pP[l(x)=k \mid H_0]$$ that is, for the event in question to occur, both $l(x)=k$ and acceptance of $H_1$ must occur. The probability of this is computed by multiplying the (marginal) probability of $l(x)=k$ by the conditional probability of accepting $H_1$ conditional on $l(x)=k$.

Combining the three terms, we get the probability of false alarm $$= pP[l(x)=k \mid H_0] + P[l(x)>k \mid H_0].$$

Note that if one treated $H_0$ as a random event, one could compute the marginal probability of false alarm, that is, to have false alarm, we need both $H_0$ to be true and $H_1$ to be accepted. This would result in multiplying the aforementioned probability by $P[H_0]$. But, outside Bayesian framework $H_0$ is not treated as a random event, and thus only probabilities of accepting $H_1$ that can be defined are the ones given $H_0$ or given $H_1$.