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

Code before:
        mock_agent.async_recognize_intent = AsyncMock(return_value=None)
        mock_get_agent.return_value = mock_agent

        result = await intent.async_handle(
            hass,
            "test",
            intent.INTENT_START_TIMER,
            {
                "name": {"value": timer_name},
                "seconds": {"value": 5},
                "conversation_command": {"value": test_command},
            },
            device_id=device_id,
            conversation_agent_id=agent_id,
        )

        assert result.response_type == intent.IntentResponseType.ACTION_DONE

        # Verify the sentence trigger was checked
        mock_agent.async_recognize_sentence_trigger.assert_called_once()

        # Verify timer was created with conversation_command
        timer_manager = hass.data["intent.timer"]
        assert len(timer_manager.timers) == 1
        timer = list(timer_manager.timers.values())[0]
        assert timer.conversation_command == test_command


async def test_start_timer_with_invalid_conversation_command(
    hass: HomeAssistant, init_components
) -> 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,

Review comment (suggestion):
```suggestion
        # Verify timer was created successfully
        timer_manager = hass.data[TIMER_DATA]
        assert len(timer_manager.timers) == 1
```

Code after:
                "seconds": {"value": 5},
                "conversation_command": {"value": test_command},
            },
            device_id=device_id,
            conversation_agent_id=agent_id,
        )

        assert result.response_type == intent.IntentResponseType.ACTION_DONE

        # Verify the sentence trigger was checked
        mock_agent.async_recognize_sentence_trigger.assert_called_once()

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


async def test_start_timer_with_invalid_conversation_command(
    hass: HomeAssistant, init_components
) -> 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

    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
    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"